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 install tomcat8 in docker

1. Install tomcat8 with docker 1. Find the tomcat...

WeChat applet learning wxs usage tutorial

What is wxs? wxs (WeiXin Script) is a scripting l...

Detailed explanation of the difference between alt and title

These two attributes are often used, but their di...

How to write asynchronous tasks in modern JavaScript

Preface In this article, we'll explore the ev...

Detailed steps for installing, configuring and uninstalling QT5 in Ubuntu 14.04

1. I downloaded QT5.13 version before, but after ...

Document Object Model (DOM) in JavaScript

Table of contents 1. What is DOM 2. Select elemen...

Bug of Chinese input garbled characters in flex program Firefox

Chinese characters cannot be input in lower versio...

JavaScript implements constellation query function with detailed code

Table of contents 1. Title 2. Code 3. Results IV....

Example code for implementing dotted border scrolling effect with CSS

We often see a cool effect where the mouse hovers...

MySQL data analysis storage engine example explanation

Table of contents 1. Introduce cases 2. View the ...

jQuery implements nested tab function

This article example shares the specific code of ...

How to write the introduction content of the About page of the website

All websites, whether official, e-commerce, socia...

MySQL executes commands for external sql script files

Table of contents 1. Create a sql script file con...