SoFunction
Updated on 2025-03-09

Docker study notes: Getting started with docker

Some questions about learning

  1. How to hot update images? (You can quickly start or destroy containers. This time is almost real-time)
  2. How to update the game server?
  3. The advantage is that the environments between each application are independent of each other, and even if a container crashes, it will not affect other containers;
  4. How to maintain each container using port? (Method 1 is written in Dockerfile, inflexible; Method 2 is specified when running;
  5. In this case, there will be many Linux users, which means that each container needs to maintain a physical machine (virtual);
  6. A set of tools is needed to manage and maintain the operations and status of images, containers;

In what scenarios are the mainstream use of docker currently used?

1. Two docker software

Docker: an open source container virtualization platform;
Docker Hub: Software-as-a-Service platform, used to share and manage docker containers.

2. The three major modules of docker

Docker images.(mirror)
Docker registries.(repository)
Docker container.(Container)

3. Commonly used commands

3.1. Commonly used mirror commands

docker image (view mirror information)
docker build (create an image)
Dockerfile
'#comment'
Which image is based on FROM
MAINTAINER Maintainer Information
RUN Run command
ADD Copy local files to the mirror
EXPOSE Settings Open Port
Programs allowed after the CMD container is started
WORKDIR Switch working directory
-t Add tag
The path needs to be connected after the build

3.2. Use less mirroring commands

docker pull (get mirror)
docker push (upload image)
docker search (search for mirror)
-s N Only search for images with specified star rating or above
docker rmi (delete the mirror)
docker tag [id] [new name:tag] (modify tag)
docker save (save the image)
docker load (load the image)
docker load --input
docker load <
The difference between load and import, mirror is complete and snapshots are discarded history and metadata information.
docker rmi $(docker images -q -f "dangling=true")(clean all local images that have not been tagged)

3.3. Common container commands

docker run([download the image and] start the container)
-t Assign a pseudo-terminal
-i Open standard input
-d background operation
-v Create and mount data volumes (multiple)
--volumes-from Mount data volumes (multiple)
-p Specify the mapping port (ip:port:containerPort/udp|ip::containerPort|port:containerPort)
-P Random map port
--name Custom container name
--rm Delete the container immediately after termination
--link : Container interconnection
docker start (start terminated container)
docker stop (terminating container)
nsenter (enter the container) (recommended)
PID=$(docker inspect --format "{{ . }}" )
nsenter --target $PID --mount --uts --ipc --net --pid

3.4. Use less container commands

docker commit (commit container)
-m --massage="" Submit information
-a --author="" Author information
-p --pause=true Pause the container run when submitting
docker attach (enter the container)
docker ps (see running container)
-a View terminated
docker logs [container ID or NAMES] View (background) run log
docker export (export container as file)
docker export >
docker import (file snapshot import image)
cat | docker import - test/name:v1.0
docker import test/name
docker rm (delete container)
Running containers will not be deleted by default
docker rm $(docker ps -a -q) Clean all terminated containers
-v Delete data volumes at the same time

4. Install

4.1. Install in CentOS7

curl -sSL / | sh    //Download the official server script accordingchkconfig docker on              //Set the power on automatically start

4.2. Install in CentOS6

4.2.1. Add yum software source


tee /etc// << 'EOF'
[dockerrepo]
name=Docker Repository
baseurl=/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=/gpg
EOF

4.2.2. Install docker

yum update
yum install -y docker-engine

4.2.3. No module named yum

If a No module named yum error occurs when executing yum update, it may be caused by the existence of a python version that does not correspond to yum. The python version can be specified by modifying the annotation of the execution scripts of yum and yum-updatest (/usr/bin/yum and /usr/bin/yum-updatest). for example:

#!/usr/bin/python
Modified to
#!/usr/bin/python2.6

5. Basic environment

You can download the bashrc_docker file and load it into the environment.bashrc. It can provide some convenient commands for some more complicated processes.

.bashrc_docker(/yeasy/docker_practice/master/_local/.bashrc_docker) The following command is defined

- docker-pid (get container pid)
- docker-enter (enter into container)
Download and load into linux environment:

wget -P ~ /yeasy/docker_practice/master/_local/.bashrc_docker
echo "[ -f ~/.bashrc_docker ] && . ~/.bashrc_docker" >> ~/.bashrc;source ~/.bashrc

6. Warehouse

6.1. Private warehouse

The official server provides a docker-registry image for the construction of private warehouses.

docker run -d -p 2010:5000 registry

vi /etc/docker/
{"insecure-registries":[":5000"]}

cul :2010/v2/linerl/tags/list

API documentation:/docker/distribution/blob/master/docs/spec/

7. Some conclusions after learning

Most servers implemented by virtual machine technology have the nature of being scalable and upgradeable at any time, and there is no need for resource allocation, and there is no need to use docker;
Docker is suitable for web services that do load balancing short links. The application scenarios are best based on mirrors and containers as the operating units;
If there is a business that can be maintained by mirroring and containers, it means that this business is very suitable for using docker.

The above is just some of the understandings I have just learned at the beginning. Of course, I still haven’t understood the ability of docker. There must be many suitable scenarios. The current records are only for future review and study consolidation.