How Do You Create a Docker Container?

Problem scenario
You want to create a Docker container.  What do you do?

Solution

Prerequisites
This assumes you have installed Docker on your Linux server.  If you have not, click the link below corresponding with your distribution of Linux:

CentOS/RHEL/Fedora
Debian/Ubuntu
SUSE

If you want to use a Dockerfile to build a Docker image, see this posting.

Procedures
1.  Find the image ID to base the container on.   Run this command:  docker images

# In the output, look for an alphanumeric value under the "IMAGE ID" column that corresponds with the REPOSITORY and TAG that you entered when creating the image.  (For example, to create a Docker image, you may have run a command like this:  docker build -t "foobar:contint".)

The output of the "docker images" command include something like this:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
foobar              contint             d2b34ea87bda        3 seconds ago       465 MB

2.  Create the container with this command:  docker create -it d2b34ea87bda bash
# Replace "d2b34ea87bda" with the image ID that you want the container to be created out of.

3.  This step is optional, but if you want to use your Docker container, run these three commands:

docker ps -a  # find the container ID
docker start 5e0bc0b18e36  # replace "5e0bc0b18e36" with the container ID associated with the output from the above command.  It should be identifiable because of the CREATED column is temporal (and based on when the container was created)

docker exec -it 5e0bc0b18e36 bash #  replace "5e0bc0b18e36" with the container ID used in the above command

4.  This step is optional.  If you want more information about this whole process, see this external link.

Leave a comment

Your email address will not be published. Required fields are marked *