Docker-Compose summary

1. Docker Compose Introduction and Installation

Docker Compose is a method for creating and starting Docker application tool by using a single command. We can use it to configure the application service.

It is a tool for development, testing and upgrading the environment.

It provides the following commands to manage the entire life cycle of the application:

  • Start, stop and reconstruction services
  • View the running status of the service
  • Streaming services running log output
  • Run-time command in the service

To achieve docker compose the installation, you need to include the following steps:

The following is a description of the installation Docker Compose Ubuntu system:

-L curl https://github.com/docker/compose/releases/ to this web site can be downloaded directly, but I have come in ahead of time to download a good drag can be installed

 

  • The application environment variable in Docker file to a publicly accessible.
  •     View the environment variables using the command: cat / etc / environment
  •     Specific environment variables to show you is:
  •     In other words we have downloaded docker compose a put to use in any environment variable
  •     Use mv docker-compose / usr / bin to move the docker compose the directory to

   

 

     This time we can see the permissions and group permissions for suchuanqi read and write, but can not perform, but can not perform, so to modify the permissions

     Use the command chown -R root: root docker-compose modified, as shown below:

    

 

     Then set executable permissions specific commands as follows: chmod + x docker-compose, i.e. it executable:

    

 

     Then use the command docker-compose version to version of view, and verify can be executed

Note that we are based on real operating Docker Docker Compose to operate

 

2. Docker Compose use

Create a docker-compose.yml profile:

root @ localhost: / usr / local / docker / tomcat # vi docker-compose.yml created here, docker-compose.yml file and write the following content

Note: In the configuration file is not capable of writing a tab key can only use the spacebar to indent

version: '3'

services:

  webapp:

    restart: always

    image: training/webapp

    container_name: webapp

    ports:

      - 5000:5000

 

 

 

Here is the inside of my computer configuration

version: '3' to develop server parse version

services: To start the server list

  tomcat: name of the server is tomcat, not just from repeat

    restart: always represented here as long as docker-compose then start tomcat always followed the start

    image: tomcat represented here as a mirror name tomcat, if not automatically go docker remote warehouse district got me a mirror

    container_name: tomcat start casually, but can not be a repeat of

    ports: Port Number Mapping

      - "8080:8080"

~                                                                                                                                                                     

 

                                                                                                                                                        

~                                 

Parameter Description:

  • version: Specifies the script syntax interpreter version
  • services: the list of services to be started
  • webapp: service name, you can easily named, can not be repeated
  • restart: start-up mode, always here means always start, even if the server is restarted, they would immediately start the service
  • image: image name, the default download from Docker Hub
  • container_name: vessel name, you can easily named, can not be repeated
  • ports: port mapping column list, left for the host port, the right for the container port

Foreground:

suchuanqi @ UbuntuBase: / usr / local / docker / python $ docker-compose up reception start command docker-compose up, but this is not a good operation will occupy the main thread, other threads to stop operations

Creating network "python_default" with the default driver

Creating webapp ...

Creating webapp ... done

Attaching to webapp

webapp    |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Background process:

suchuanqi @ UbuntuBase: / usr / local / docker / python $ docker-compose up -d Here is the background to start docker-compose, will not take up the current main thread

Creating webapp ...

Creating webapp ... done

lusifer@UbuntuBase:/usr/local/docker/python$

running result:

 

 

By docker-compose we can start the tomcat, tomcat log to print work through docker-compose logs -f tomcat, you can see the log

 

 

3. Docker Compose command

Foreground

docker-compose up

Background process

docker-compose up -d

start up

docker-compose start

stop

docker-compose stop     注意停止的时候必须在有docker-compose.yml的配置文件中进行使用

Stop and remove the container

docker-compose down      这里的删除是在docker ps -a 删除tomcat容器的,因为我的tomcatdocker-compose里面进行设置

 

 

 

 

4. Docker Compose tutorial examples:

Docker Compose run Tomcat

docker-compose.yml Profiles:

version: '3'
services:
  tomcat:
    restart: always
    image: tomcat
    container_name: tomcat
    ports:
      - 8080:8080
    volumes:
      - /usr/local/docker/tomcat/webapps/:/usr/local/tomcat/webapps/
    environment:
      TZ: Asia/Shanghai
 
 
开启tomcat后记得在webapps里面创建一个ROOT文件夹,然后在里面创建一个index.html以供测试使用

Docker Compose run mysql

创建docker-compose.yml Profile: Using vi docker-compose.yml创建该文件并进行编译操作

version: '3'
services:
  mysql:
    restart: always
    image: mysql:5.7
    container_name: mysql
    ports:
      - 3306:3306
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: 123456
    command:
      --character-set-server=utf8mb4                    这里是设置字符及UTF-8 
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1                        这里是忽略大小写
      --max_allowed_packet=128M
      --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
    volumes:
      - mysql-data:/var/lib/mysql
 
volumes:
  mysql-data:

We can view the log by docker-compose logs -f mysql

First off when you shut down any services on docker-compose must be entered to have docker.compose.yml folder using the docker-compose down to shut down, you can not use similar docker stop xxxx and so named because it is closed then there is no use docker-compose the hosting

 

 

 

Arranged in succession docker-compose the environment is configured MySQL Tomcat together, as shown below, and then a deployment project:

 

 

We can access the path to mysql data files stored by / var / lib / docker / volumes

Guess you like

Origin www.cnblogs.com/chuanqi1995/p/11424158.html