Docker Container

Docker Container is a running instance of a 202202211632#. There are various 202110201636# commands that interact with the 202204071114#.

To start a container instance, run the command docker run {image-name}. If the 202202211632# does not exist in the local machine, it will instead pull from remote or local repository, and then run it afterwards if the pull is successful. See 202202211632 for more information about the docker pull. If specific version of image should be downloaded, define the tag in the format {image-name}:{tag}. Otherwise, it will always download the latest tag version of the image.

If the default process (defined as CMD, specified in 202110201654#) is not the one you desire, you could override it with the format docker run {image-name} {CMD}.

There are several options could be pass to docker run:

  • -d to detach the container to the background,
  • -i to run the container instance in an interactive mode,
  • -t to attach a pseudo-terminal to the container,
  • -e {environment-variable}={value} to set environment variable,
  • -p {client-access-port}:{app-listen-port} to establish a socket,
  • -v {volume-name}:{path} to attach a persistent volume,
  • --name to name the container,
  • --link to establish a connection between two containers, (deprecated)
  • --cpus={percent} to limit the CPU usage (using #202204071051),
  • --memory={size} to limit the memory usage (using #202204071051)

A detached container could be brought up again by calling docker attach {container-id}/{container-name}. It will then occupy the current shell just like the default behaviour of docker run.

docker exec {container-id}/{container-name} {commands} could be used to execute the commands inside the specified container.

docker ps lists all running containers in the local machine. If you want to see more than just the running instances, you could pass in the option -a for more verbosity.

We could obtain the detail information about the container by using two commands: docker inspect {container-id}/{container-name} or docker logs {container-id}/{container-name. docker inspect will output the information into JSON format whereas the docker logs will output the log instead if the container is running.

In order to stop a container, we could use the command docker stop {container-id}/{container-name} where we pass in either container ID or its name. These information could be obtained from the command docker ps.

Removing a container could be as easy as calling the command docker rm.

Container Layer

Upon running, #202110201636 will create a layer on top of image layer (describe in #202110201654). The changes of file which located in image layer will be done in #202203251058 where all the changes will happen in container layer.

If the container stop running, all the changes or data will vanish. To store those information, attach the container to 202203251354.

Links to this page
  • Docker Volume

    Docker could attach a Docker Volume or an external directory to a 202203281423 using the option -v in docker run. Attaching a Docker Volume to a container is call **volume mount** with the format {volume-name}/{path}whereas attaching an external directory to a container is call **bind mount**{dir-path}/{path}`.

  • Docker Image

    #202110201636 Image is simply a template for building #202203281423. It simplifies the software deployment in Linux distributions by the DevOps.

    We could download a specific image from #202203251430 by executing docker pull {registry}/{username}/{image-name} without having the #202203281423 running. If specific version of image should be pulled, define the tag in the format {image-name}:{tag}. Otherwise, it will always pull the latest tag version of the image.

  • Docker File

    There is a layer that run on top of image layer. It is container layer. See #202203281423.

  • Docker Compose

    docker-compose could be used to run multiple #202110201655 #202203281423 in a single Docker host using a YAML file. Name the following YAML file as docker-compose.yaml or later use the option -f to import the file:

  • Docker CLI
#container #networking #)