Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paalamugan/docker-compose-configuration
Configuration of multiple docker-compose.yml service file examples.
https://github.com/paalamugan/docker-compose-configuration
docker docker-compose docker-setup dockerfile
Last synced: about 2 months ago
JSON representation
Configuration of multiple docker-compose.yml service file examples.
- Host: GitHub
- URL: https://github.com/paalamugan/docker-compose-configuration
- Owner: paalamugan
- Created: 2021-12-30T12:14:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-17T18:37:08.000Z (over 2 years ago)
- Last Synced: 2024-05-17T20:53:38.645Z (8 months ago)
- Topics: docker, docker-compose, docker-setup, dockerfile
- Language: Dockerfile
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Docker Compose Configuration
Configuration of multiple docker-compose.yml service file examples.
## How to install docker compose
- Download the docker-compose file
```sh
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
```- Add executable permission to the file.
```sh
sudo chmod +x /usr/local/bin/docker-compose
```- Test installation results.
```sh
docker-compose --version
```## [Dockerfile instructions](https://docs.docker.com/engine/reference/builder/)
Before understanding Docker compose, you need to understand Dockerfile.
### FROM
Specify the base image, usually the first instruction of the file, but in fact, you can also use ARG as the first instruction.```
# Format
FROM [--platform=] [AS ]
FROM [--platform=] [:] [AS ]
FROM [--platform=] [@] [AS ]# Usage
FROM ubuntu
FROM openjdk:8-jre
FROM node:12.18.4-alpine@sha256:757574c5a2...
```
**Parameter Description:**
- `[--platform=]` is an optional parameter, which can be used to specify the platform of the image, such as Linux/amd64, Linux/arm64, or windows/amd64, usually the default.
- `` is the image name, followed by `:tag` is the version number used to specify the image, and `@digest` is the content-addressable identifier (you can go to the official website for details). Generally, we only use tags. If two If neither is specified, the latest version is obtained
- `[AS ]` is the name of the current build stage, because multiple FROMs can be used in the Dockerfile to create multiple images, so using as `` can be used in the following COPY command, use `--from=` to refer to the image built earlier, such as copying the files generated by the previous image, etc.### ARG
This command is used to specify a variable that is passed to the build runtime. It can set a default value. When building a container with the `docker build` command, use `--build-arg =` to pass parameters.```
# Format
ARG [=]# Usage
ARG CODE_VERSION=laster
ARG testArg=123# Parameter
FROM centos:7
ARG parameter=123
RUN echo $parameterdocker build --build-arg parameter=234 -t test:1.0
# Note
# ARG can be used before FROM, outside of the FROM build phase, so it cannot be used in any instructions after FROM.
ARG UBUNTU_VERSION=laster
FROM ubuntu:${UBUNTU_VERSION}
```### ENV
This command is used to set environment variables for the container, both during the build process and in the launched container.```
# Format
ENV = ...# Note
# More than one can be set, or another syntax ENV can be used. The official website recommends using the former, and the latter may be deleted in future versions.
# ENV variables override ARG variables# Usage
ENV APP_VERSION=1.1.0
ENV WEB_HOME /opt/webapps
```### COPY
This command is used to copy files or directories from the path to the container.```
# Format
COPY ...
COPY "",... ""# Usage
COPY test.js /opt/web/
```### ADD
This command is used to copy files, directories, or remote files to the image, and the tar-type compressed package file will be automatically decompressed.```
# Format
ADD ...
ADD "",... ""# Usage
ADD test.txt /tmp/test
```### WORKDIR
This command sets the working directory for subsequent directives, if it does not exist, the directory will be created automatically.```
# Format
WORKDIR /path/to/workdir# Usage
WORKDIR /build
```### LABEL
This command is used to specify the metadata tag information of the image.```
# Format
LABEL = = = ...# Usage
LABEL version="1.0"
LABEL description="This text illustrates"
```### CMD
This command is used to set the command to be executed when the container starts after building the image.```
# Format
CMD ["executable","param1","param2"]
CMD ["param1","param2"]
CMD command param1 param2# Usage
CMD sleep 40; node server.js
CMD ["node", "server.js"]
```### RUN
This command is used to specify the command to be executed when building the image. The main difference between RUN and CMD is that CMD is executed when the container starts, while RUN is executed during the container construction.```
# Format
RUN
RUN ["executable", "param1", "param2"]# Usage
RUN apt install -y net-tools
RUN ["/bin/bash", "-c", "echo helloworld"]
```### EXPOSE
This command is used to specify that the container is running on the specified port. You can specify the listening protocol. If not specified, the default is TCP.```
# Format
EXPOSE [/...]# Usage
EXPOSE 80/udp
EXPOSE 80 443
```### VOLUME
This command is used to create a mount point with the specified name that can map the directory outside the container.```
# Format
VOLUME ["/data"]# Usage
VOLUME /myvol
```## [Docker common commands](https://docs.docker.com/engine/reference/commandline/docker/)
- build: Build container.
- ps: List all containers of the current project.
- up: Build the container and start the container, common parameters: -d background start, - specify the configuration file.
- exec: Into the specified container.
- top: View the running status of each container in the project.
- logs: View the output of the container.
- down: Stop and remove all containers and remove the corresponding network.
- rm: Remove all stalled containers.
- start/stop/restart: Start container/stop container/restart container.## [Docker compose file structure](https://docs.docker.com/compose/compose-file/)
- version: Specify the compsoe version corresponding to the current file, mainly 1, 2.x and 3.x
- services: service list
- [service-name]: service name
- image: Specify the running image, you can directly pull the existing image for processing
- build: Set the folder where the Dockerfile is located, which can process images that need to be built with Dockerfile
- content: the path to store the Dockerfile
- dockerfile: Specifies the Dockerfile filename for the build
- args: build arguments, only accessible during the build process
- container_name: set the container name
- restart: restart strategy, there are no, always, no-failure, unless-stoped
- ports: Expose the port of the container, the format is host port: container port
- 8080:8080
- hostname: set the hostname of the container
- volumes: Set the mount point of the container, which can be mounted on the host, the main format is `"host path":"container path"[: "access mode(w,r,rw)"]`
- /opt/data:/opt/data
- /var/lib/mysql:/var/lib/mysql:rw
- volumes_from: mount all data volumes of another service or container
- service_name
- container_name
- environment: set environment variables
- RACK_ENV=development
- networks: configure networks
- app_netwotk: