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.
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
httpdimage.
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 from the
httpdimage.
- If this is the first time you enter this command

- If this is not the first time you enter this command

- Check if the container has been created.

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.
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-httpdfrom thehttpdimage.
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-httpdfrom thehttpdimage.

- Check if the container has been created.

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.
Map Ports
In this sub-challenge, you will learn how to map ports using the -p option.
Target
- Map port
8080on the host to port80in a container calledmy-httpd2.
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-httpd2from thehttpdimage and map port8080on the host to port80in the container.

- Check if the host port mapping is in the container configuration.

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.
Set Environment Variables
In this sub-challenge, you will learn how to set environment variables using the -e option.
Target
- Set the
NGINX_HOSTenvironment variable toexample.comin a container calledmy-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-httpd3from thehttpdimage and set theTEST-ENVenvironment variable totest-valuein the container.

- Check if the environment variable is in the container configuration.

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.
Mount Volumes
In this sub-challenge, you will learn how to mount volumes using the -v option.
Target
- Mount the
/var/wwwdirectory on the host to the/usr/share/nginx/htmldirectory in a container calledmy-httpd4.
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-httpd4from thehttpdimage and mount the/var/wwwdirectory on the host to the/usr/share/nginx/htmldirectory in the container.

- Check if the volume mount of the container is configured in the container.

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.
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.



