Detailed process of getting started with docker compose helloworld

Detailed process of getting started with docker compose helloworld

Prerequisites

Compose is a tool for orchestrating Docker containers. It is a powerful tool for integrating and publishing Docker applications. It can define and run multi-container applications. In Compose, you can use YAML files to configure your application services. Then, with just one simple command, all the services you configured are created and started.

Docker-compose is based on Docker, so we need to install Docker before we can use Docker-compose.

Using Compose basically involves the following three steps:

Define your application environment in Dockerfile, which can be multiple docker applications.
Define the services that make up your application in docker-compose.yml.
Run the entire application solution using the docker-compose up command.

Reference URL:

Docker installation

  • Uninstall old versions
sudo yum remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
              docker-logrotate \
                docker-engine
  • Install Docker Engine-Community
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager \
  --add-repo \
  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
  • Start Docker
sudo systemctl start docker
  • Install the plugin
yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm
  • Test whether Docker is installed successfully
docker --version

到此docker安裝完成!!!

docker-compose installation

The official website download address may be slow, it is recommended to use the following

  • Download and install
curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  • Authorization (must be authorized, responsible for not having authority)
chmod +x /usr/local/bin/docker-compose
  • Verify that docker-compose is installed successfully (check the version)
docker-compose version 

image-20210918114058939

到此docker-compose 安裝成功!!!

Getting Started with Docker Compose

Generate mysql and redis containers through docker-compose

1. Create a project directory and enter

$ mkdir composetest
$ cd composetest

2. Create a docker-compose.yml file and put it in the project directory

The specific contents of the file are as follows:

version: "3.0"
services:
  mysqldb:
    image:mysql:5.7.19
    container_name: mysql
    ports:
      - "3306:3306"
    volumes:
      - /root/mysql/conf:/etc/mysql/conf.d
      - /root/mysql/logs:/logs
      - /root/mysql/data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
    networks:
      -ems
    depends_on:
      - redis

  redis:
    image: redis:4.0.14
    container_name: redis
    ports:
      - "6379:6379"
    networks:
      -ems
    volumes:
      - /root/redis/data:/data
    command: redis-server
    
networks:
  ems:

3. Start

Start in current folder

  • Front desk startup

docker-compose up

  • Background startup

docker-compose up -d

The output log is as follows

image-20210918114856486

Check whether the container in Docker is available

Check whether the container is generated

image-20210918115145469

Test whether the redis container is available

image-20210918115226368

Test whether the mysql container is available

image-20210918115329685

到此入門案例已經完成!!!

Summarize

1. The docker-compose command cannot be executed because of a permission issue. We need to open permissions and execute the following command

chmod +x /usr/local/bin/docker-compose

2. During the study period, we can use docker-compose in the virtual machine to build our basic hardware facilities, which is very convenient and saves a lot of time in configuring the environment and installing basic services.

3. Docker-compose still needs to be learned

Reference URL:

https://mp.weixin.qq.com/s/KXUm2ydAgymaNzHDiMlg0g

The pitfall of insufficient permissions

https://blog.csdn.net/weixin_41598660/article/details/104034179

This is the end of this article about getting started with docker compose helloworld. For more information about getting started with docker compose helloworld, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • A brief discussion on how to solve the depends_on order problem in Docker-compose
  • Practical notes on installing Jenkins with docker-compose
  • Docker Compose installation and usage steps
  • Detailed explanation of the Sidecar mode in Docker Compose

<<:  Master-slave synchronization configuration of Mysql database

>>:  Solution to span width not being determined in Firefox or IE

Recommend

How to create a stylish web page design (graphic tutorial)

"Grand" are probably the two words that ...

Vue implements simple calculator function

This article example shares the specific code of ...

How to use Nginx to proxy multiple application sites in Docker

Preface What is the role of an agent? - Multiple ...

HTML pop-up div is very useful to realize mobile centering

Copy code The code is as follows: <!DOCTYPE ht...

JavaScript Function Currying

Table of contents 1 What is function currying? 2 ...

Classes in TypeScript

Table of contents 1. Overview 2. Define a simple ...

Solution to the problem of repeated pop-up of Element's Message pop-up window

Table of contents 1. Use 2. Solve the problem of ...

Vue implements start time and end time range query

This article shares with you how to query the sta...

Docker deploys mysql to achieve remote connection sample code

1.docker search mysql查看mysql版本 2. docker pull mys...

jQuery implements shopping cart function

This article example shares the specific code of ...