Docker

The Docker platform was created to make the process of creating, distributing, and executing applications easier.

Applications and their dependencies are packaged by Docker using containerisation technology into a standardised unit known as a container. Containers are perfect for developing, testing, and deploying applications because they are small, portable, and operate consistently in a variety of contexts.

Go to the Docker website at Docker Desktop: The #1 Containerization Tool for Developers | Docker to download the Docker-desktop for your operating system.

Follow the instructions to install Docker-desktop in your computer.

You can confirm the success of your Docker installation via any Command Line Interface (CLI) using this command docker --version

Using Visual Studio Code (download site: Download Visual Studio Code - Mac, Linux, Windows), create a working directory. Go to File - Open Folder - choose location on your computer - select existing or create new folder - click on Select Folder

The selected folder becomes your working directory.

After creating your working directory, open the terminal in your Visual Studio Code.

Clone the repository for the sample application using the git clone command

  • git: This is the command-line tool used for version control with Git.

  • clone: This subcommand tells Git that you want to clone (or make a copy of) a repository.

  • https://github.com/docker/welcome-to-docker: This is the URL of the repository you want to clone. It points to a GitHub repository named welcome-to-docker under the docker organization.

Putting it all together, this command tells Git to copy the repository located at https://github.com/docker/welcome-to-docker to your local machine. This means you'll have a local copy of all the files and history from that repository, which you can then work on or modify.

On the left pane of your Visual Studio Code, you will see the cloned repository sample application.

Change directory to the folder housing your Dockerfile. You can view the content in the Dockerfile by clicking on it

Notice that the welcome-to-docker directory has been added.

It is time to build your first image using the command docker build -t welcome-to-docker .

  • docker build: This is the Docker command used to build an image from a Dockerfile.

  • -t welcome-to-docker: The -t flag allows you to tag the image with a name. In this case, you're tagging the image with the name welcome-to-docker.

  • . (dot): This specifies the build context, which is the current directory. Docker will look for a Dockerfile in this directory to build the image.

Putting it all together, this command tells Docker to build an image from the Dockerfile in the current directory and tag it with the name welcome-to-docker.

It can take some time to build the image. Once your image has been constructed, you may see it in Docker Desktop's Images tab.

Open the Docker Desktop you downloaded earlier on your local machine. Click on your image in the Images tab

Click on Run at the top right corner of your image window

Click on the dropdown arrow for Optional settings

Container name is optional as a container name can be generated if not provided.

Give it a Host port.

Click on Run

In your container tab, click on the link depicting the port you provided - host port (in this documentation: 8089) and the the port in the docker container: 3000

8089:3000

You can check the logs of your running container from the container tab

You can check your running containers.

0
Subscribe to my newsletter

Read articles from Adekunle Fatunde directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Adekunle Fatunde
Adekunle Fatunde