Detailed installation and use of docker-compose

Detailed installation and use of docker-compose

Docker Compose is a Docker tool for defining and running complex applications. With Docker Compose you no longer need to use shell scripts to start containers. (Configured via docker-compose.yml)

Installation of Docker Compose

Github Source

sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# Add executable permissions to docker-compose sudo chmod +x /usr/local/bin/docker-compose

Daocloud Source

curl -L https://get.daocloud.io/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# Add executable permissions to docker-compose sudo chmod +x /usr/local/bin/docker-compose

Uninstalling Docker Compose

sudo rm /usr/local/bin/docker-compose

Check the version of Docker Compose

docker-compose --version

Configure Dockerfile

#Specify the base image and customize it FROM java:8

#Maintainer information MAINTAINER zhouzhaodong <[email protected]>

#Set the working directory WORKDIR /apps/demo

#Add demo-0.0.1-SNAPSHOT.jar to the container ADD demo-0.0.1-SNAPSHOT.jar demo-1.0.0.jar

#Execute in bash mode to make demo-1.0.0.jar accessible. #RUNCreate a new layer and execute these commands on it. After the execution is completed, commit the changes of this layer to form a new image.
RUN bash -c "touch /demo-1.0.0.jar"

#Declare the service port provided by the runtime container. This is just a declaration. The application will not open the service of this port at runtime because of this declaration. EXPOSE 8080

#Specify the container startup program and parameters <ENTRYPOINT> "<CMD>"
ENTRYPOINT ["java","-jar","demo-1.0.0.jar"]

Configure the docker-compose.yml file

# Version: '3.0'
services:
 demo:
  # build is used to specify the file path where the Dockerfile is located build: .
  # Mapping ports ports:
  - "8080:8080"
  volumes: #Specify a file directory to store container data.
  # $PWD represents the current path - $PWD/data:/var/lib/log

Common commands for docker-compose

build: #Build image without cache docker-compose build --no-cache;
up: # Build and start the container docker-compose up -d
down: # Delete all containers, mirror docker-compose down
restart: #Restart the container docker-compose build; docker-compose down; docker-compose up -d

Run the docker-compose command to build and run the image

  • First, create a new folder in the host machine to store the Dockerfile, docker-compose.yml and the jar package we created earlier.
  • First enter the directory and run the down command to delete all previously created images.
  • Run the build command to generate the image.
  • Run the up command to start the container.
  • Access the ip+port number and you can see our program.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Two simplest ways to install docker-compose
  • Detailed explanation of common Docker Compose commands
  • Docker Compose Tutorial
  • Detailed examples of using Docker-Compose
  • Detailed explanation of how to use Docker-Compose commands
  • Docker compose configuration file writing and command usage examples

<<:  How to implement MySQL bidirectional backup

>>:  Vue mobile terminal realizes finger sliding effect

Recommend

How does Vue download non-same-origin files based on URL

Generally speaking, we can have the following two...

The magic of tbody tag speeds up the display of table content

You must have saved other people’s web pages and l...

Example code for implementing WeChat account splitting with Nodejs

The company's business scenario requires the ...

How to run Spring Boot application in Docker

In the past few days, I have studied how to run s...

Implementing search box function with search icon based on html css

Preface Let me share with you how to make a searc...

Two simple ways to remove text watermarks from web pages

<br /> When we browse certain websites and s...

Solution to the problem that Navicat cannot remotely connect to MySql server

The solution to the problem that Navicat cannot r...

CSS inheritance method

Given a div with the following background image: ...

How to deploy Vue project using Docker image + nginx

1. Packaging Vue project Enter the following name...

Getting Started Tutorial for Beginners: Domain Name Resolution and Binding

So after registering a domain name and purchasing...

The docker-maven-plugin plugin cannot pull the corresponding jar package

When using the docker-maven-plugin plug-in, Maven...

How to use cc.follow for camera tracking in CocosCreator

Cocos Creator version: 2.3.4 Demo download: https...

css3 animation ball rolling js control animation pause

CSS3 can create animations, which can replace man...