Tutorial: Installing Docker and Cloning A Containerized Web Server

Installing Docker and Cloning A Containerized Web Server

Docker Tutorial

  1. Installing Docker ……………………………………………………………….
  2. Pulling Repository/Image ……………………………………………………..
  3. Running Container …………………………………………………………….
  4. Building a Docker Image……………………………………………………..
  5. Troubleshooting Problems & Solutions …………………………………….

Installing Docker

Go to https://hub.docker.com and login to your account.

  • If you don't already have a Docker account, you will need to create one

  • It's free to create, select the free plan ↓

  • Verify your email
  • Download Docker Desktop Application

- Verify Docker installed by running the command\> docker
  - Should result in a list of docker help commands
  • Open the Docker Desktop Application
    • Docker will prompt you to allow privileges, allow it
    • Accept the service agreement
  • Sign In on the Docker Desktop Application ↓

Pulling Repository/Image

Go to docker repository:

https://hub.docker.com/repository/docker/jtamwaffle/visual/general

Copy the command ↓

Open a terminal and enter the command> docker pull jtamwaffle/visual

  • You should see this when its finished ↓
  • To check if the repository pulled, enter the command> docker images You should see the following ↓

Running Container

Now that the image is pulled, you can run it through the terminal or you can run it through the Docker Desktop Application. I will show how to run it through the Docker Desktop Application first:

  • In the desktop application, click the Images tab on the left ↓
  • Then, click run for the image you want to create a container for ↓ This window should pop up to run a new container, go to Optional Settings
  • Go to Ports -> Host Port and enter the port number to run on your local machine. I chose port 8080 for this tutorial ↓
    • This port number is the local host your machine will use to run and view the container
    • The default port the container will use is 8000
  • Then, run the container ↓
  • You should be taken to the Container tab and see the following ↓
    • You can also validate the container is running in the terminal by using the command> docker ps
      • You should see the following

To run the application through the terminal

  • Use the command> docker run -d -p <local port>:8000 <image ID>
    • If you do not know the image ID
      • Go to the Images tab in the desktop application
      • Under the image you need the ID for is the image ID ↓

When you're done using the container, you should stop the container. This can be done either by using the Docker Desktop Application or through the terminal.

  • Using the desktop application, under the Container tab, press the stop button at the top of the page for the container you want to stop ↓

  • Using the terminal, enter the command> docker stop <container ID>

    • If you do not know the container ID, enter the command> docker ps
  • The container ID will be listed in the first column ↓

Building a Docker Image

This will cover two ways to build a docker image, the first method builds a docker image from the git repository. The second method builds the docker image from a pre-existing docker image, like a copy of the docker image.

Building a Docker Image from Git Repository

  • Go to the location where you locally stored the git repository

  • Within the git repo is an already made Dockerfile that will be used for building the docker image.

  • To build the docker image, use the command> docker build -t <tagname> <path>

  • For the tagname, I recommend using your username followed by the name for the docker image

    • Ex) anc224/visual:1.0
  • Use '.' for the path to indicate that you are building the image from the current directory

  • Verify the docker image was created with the command> docker images

Building a Docker Image from a Docker Image

  • Create a Docker file

    • Command> touch Dockerfile
      • Note that there are no file extensions
  • Open Docker file

    • Command> vim Dockerfile
      • Press 'i' to enter Insert Mode
  • Type "FROM <image name>:latest"

    • Save file and exit with ":x!"
  • To build the docker image, use the command> docker build -t <tagname> <path>

  • For the tagname, I recommend using your username followed by the name for the docker image

    • Ex) anc224/visual:1.0
  • Use '.' for the path to indicate that you are building the image from the current directory

  • Verify the docker image was created with the command> docker images

Troubleshooting Problems & Solutions

Command> docker images

"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"

  • Solution: open the docker desktop application

Command> docker build -t <tagname> <path>

"ERROR: [5/7] COPY local_packages ./: failed to compute cache key: "/local_packages" not found: not found"