Docker Compose deployment service
Compose is a Docker application where the user defines and runs multiple containers. In Compose you can use yaml files to configure your application services. Then, with a simple command, you can create and start all the services you configure.
Compose can make it easy for us to quickly and efficiently manage the start, stop, restart and other operations of the container. It is similar to a shell script under linux, based on yaml syntax, in which we can describe the architecture of the application, such as what mirroring, data volume, network mode, listening port and other information are used. We can define a multi-container application (such as jumpserver) in a compose file, and then start the application through the compose.
Install compose:
Download link: https://github.com/docker/compose/releases
Wget can be downloaded, but the speed is very slow. It is recommended to download it with Windows and upload it to centos.
[root@jinkai02 src]# wget https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-x86_64
[root@jinkai02 src]# du -sh docker-compose-Linux-x86_64
12M docker-compose-Linux-x86_64
[root@jinkai02 src]# mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
[root@jinkai02 src]# chmod 755 !$
chmod 755 /usr/local/bin/docker-compose
[root@jinkai02 src]# docker-compose version
docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
Compose distinguishes between Version 1 and Version 2 (Compose 1.6.0+, Docker Engine 1.10.0+). Version 2 supports more instructions. Version 1 does not state that the version defaults to "version 1". Version 1 will be deprecated in the future.
Example:
vim docker-compose.yml #Write the following content, pay attention to spaces
version: "2" #Use version 2
services:
app1: #Indicates the container name
image: centos_nginx #Indicates the image name
ports:
-"8080:80" #Specify the mapping port
networks:
-"net1" #Specify network mode
volumes:
-/data/:/data #Directory mount, which is equivalent to the -v option mentioned earlier
app2:
image: centos_with_net
networks:
- "net2"
volumes:
- /data/:/data1
entrypoint: tail -f /etc/passwd #Prevent the dockerfile from stopping after the container runs
networks:
net1:
driver: bridge
net2:
driver: bridge
Run docker-compose:
[root@jinkai02 src]# docker-compose up -d //-d background start
Creating src_app1_1 ... done
Creating src_app2_1 ... done
[root@jinkai02 src]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
97c7e2132393 centos_with_net "tail -f /etc/passwd" 29 seconds ago Up 28 seconds src_app2_1
7e7a1f70bf27 centos_nginx "/bin/sh -c '/usr/lo…" 29 seconds ago Up 28 seconds 0.0.0.0:8080->80/tcp src_app1_1
[root@jinkai02 src]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------
src_app1_1 /bin/sh -c /usr/local/ngin ... Up 0.0.0.0:8080->80/tcp
src_app2_1 tail -f /etc/passwd Up
By using compose, we can easily manage operations such as starting, stopping, and restarting containers.
docker-compose --help
docker-compose ps/down/up/stop/start/rm
Reference document about docker-compose syntax http://www.web3.xin/index/article/182.html