Docker – Create Containers Quick Start Guide

Docker,InfrastructureDocker

Basically, you can see the all commands with “docker container –help“, but at first, I believe you need the following commands for your quick start!

Basic commands

Check version.

$ docker version

Check more details.

$ docker info

Docker command format.

$ docker [command] [subcommand] (options)

Example:

$ docker container run


Manage Containers

Create a nginx container named “proxy".

$ docker container run --publish 80:80 --detach --name proxy nginx

Show containers list.

$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec9485a76f6c nginx "/docker-entrypoint.…" 6 minutes ago Exited (0) 21 seconds ago pensive_fermat

Stop a running container.

$ docker container stop [container id]/[container name]

Start a stopped container.

$ docker container start [container id]/[container name]

Remove container.

$ docker container rm [container ID]


Monitor containers

Check container’s log.

$ docker container logs [container id]/[container name]

Monitor the processes running inside a container.

$ docker container top [container id]/[container name]

Show one container’s configuration.

$ docker container inspect [container id]/[container name]

Example 1:

$ docker container inspect proxy
[
{
"Id": "5a764b6f85edae89527643c1cad3b833a656e8666aa1dff7428c7065e2738956",
"Created": "2020-06-24T02:37:58.276872574Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"nginx",
"-g",
"daemon off;"
],
"State": {
"Status": "running",

:

:

Also, you can use filter with –format “{{}}".

$ docker container inspect --format "{{.NetworkSettings.IP Address}}" proxy

Show live performance stats for all containers.

$ docker container stats


Other examples of creating containers

Create a MySQL container named “db".

docker container run -d -p 3306:3306 --name db -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql