Docker Create Command

DockerDockerBeginner
Practice Now

Introduction

Docker is a popular platform for developing, shipping, and running applications. The docker create command is used to create a new container from an image. In this challenge, you will learn how to use the docker create command to create a new container step-by-step.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker/ContainerOperationsGroup -.-> docker/inspect("Inspect Container") docker/ContainerOperationsGroup -.-> docker/create("Create Container") subgraph Lab Skills docker/inspect -.-> lab-15817{{"Docker Create Command"}} docker/create -.-> lab-15817{{"Docker Create Command"}} end

Create a Container from an Image

In this sub-challenge, you will learn how to create a new container from an image using the docker create command.

Target

  • Create a new container from the httpd image.

Example

Here is an example of what you should be able to accomplish at the end of this step:

  1. Open a terminal or command prompt.
  2. Create a new container from the httpd image.
  • If this is the first time you enter this command
First Docker container creation
  • If this is not the first time you enter this command
Repeating Docker create command
  1. Check if the container has been created.
Verify container creation status

Hints

If the container name is already in use, you can use the docker rm -f xxx(container-name) command to remove it.

Requirements

  • Docker must be installed on your machine.
โœจ Check Solution and Practice

Name the Container

In this sub-challenge, you will learn how to name a container using the --name option.

Target

  • Create a new container called my-httpd from the httpd image.

Example

Here is an example of what you should be able to accomplish at the end of this step:

  1. Open a terminal or command prompt.
  2. Create a new container called my-httpd from the httpd image.
Creating container my-httpd
  1. Check if the container has been created.
docker container verification

Tip

If the container name is already in use, you can use the docker rm -f xxx(container-name) command to remove it.

Requirements

  • Docker must be installed on your machine.
โœจ Check Solution and Practice

Map Ports

In this sub-challenge, you will learn how to map ports using the -p option.

Target

  • Map port 8080 on the host to port 80 in a container called my-httpd2.

Example

Here is an example of what you should be able to accomplish at the end of this step:

  1. Open a terminal or command prompt.
  2. Create a new container called my-httpd2 from the httpd image and map port 8080 on the host to port 80 in the container.
docker create container port mapping
  1. Check if the host port mapping is in the container configuration.
Container port mapping check

Tip

If the container name is already in use, you can use the docker rm -f xxx(container-name) command to remove it.

Requirements

  • Docker must be installed on your machine.
โœจ Check Solution and Practice

Set Environment Variables

In this sub-challenge, you will learn how to set environment variables using the -e option.

Target

  • Set the NGINX_HOST environment variable to example.com in a container called my-httpd3.

Example

Here is an example of what you should be able to accomplish at the end of this step:

  • Open a terminal or command prompt.
  • Create a new container called my-httpd3 from the httpd image and set the TEST-ENV environment variable to test-value in the container.
Creating container with environment
  • Check if the environment variable is in the container configuration.
verify container environment variable

Tip

If the container name is already in use, you can use the docker rm -f xxx(container-name) command to remove it.

Requirements

  • Docker must be installed on your machine.
โœจ Check Solution and Practice

Mount Volumes

In this sub-challenge, you will learn how to mount volumes using the -v option.

Target

  • Mount the /var/www directory on the host to the /usr/share/nginx/html directory in a container called my-httpd4.

Example

Here is an example of what you should be able to accomplish at the end of this step:

  1. Open a terminal or command prompt.
  2. Create a new container called my-httpd4 from the httpd image and mount the /var/www directory on the host to the /usr/share/nginx/html directory in the container.
Creating container with volume mount
  1. Check if the volume mount of the container is configured in the container.
verify container volume mount

Tip

If the container name is already in use, you can use the docker rm -f xxx(container-name) command to remove it.

Requirements

  • Docker must be installed on your machine.
โœจ Check Solution and Practice

Summary

In this challenge, you learned how to use the docker create command to create a new container step-by-step. You learned how to create a container from an image, name the container, map ports, set environment variables, and mount volumes. With these skills, you can create and configure containers to run your applications in Docker.