Docker and Docker-compose

Docker is a group of platform-as-a-service (PaaS) products that use operating system-level virtualization to deliver software in packages called containers. Containers isolate each other and bundle together their own software, libraries, and configuration files; They can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines. Compose is a Docker application that is user-defined and runs multiple containers. In Compose you can use YAML files to configure your application services. You can then create and start all of your configured services with a simple command.Copy the code

2. Install Docker and Docker-compose

The installation of a docker
  • Ali cloud
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Copy the code
  • daocloud
 curl -sSL https://get.daocloud.io/docker | sh
Copy the code

It will automatically restart after installation

The docker unload

sudo apt-get remove docker docker-engine
rm -fr /var/lib/docker/
Copy the code

Configuration accelerator (the following is my Ali Cloud acceleration configuration)

mkdir -p /etc/docker
touch /etc/docker/daemon.json
vim /etc/docker/daemon.json

{"registry-mirrors": ["https://asmtpu24.mirror.aliyuncs.com"]}


systemctl daemon-reload
systemctl restart docker
Copy the code
The installation of docker – Compose

You can customize the version you need by changing the version in the URL.

  • Making the source
The curl -l https://github.com/docker/compose/releases/download/1.22.0/docker-compose- ` ` uname - s - ` uname -m ` - o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-composeCopy the code
  • Daocloud mirror
The curl -l https://get.daocloud.io/docker/compose/releases/download/1.22.0/docker-compose- ` ` uname - s - ` uname -m ` > / usr /local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
Copy the code

uninstall

sudo rm /usr/local/bin/docker-compose
Copy the code

use

① Create docker-comemage. yml file

With the following configuration, you can create two sites after you run (for demonstration only)

version: "2"
services:
  test:
    hostname: test
    image: tomcat:8
    volumes:
      - "./target/test.war:/usr/local/tomcat/webapps/test.war"
    ports:
      - "38000:8080"
    entrypoint:
      - "catalina.sh"
      - "run"
Copy the code

Docker-compose is composed for a simple demonstration

② After the construction is completed, the background runs the image

docker-compose up -d
Copy the code

After running, you can access both sites using IP +port

3 Image update and redeploy

docker-compose down
docker-compose pull
docker-compose up -d
Copy the code