Install docker
Official Portal: Installing Docker Engine on Ubuntu | Docker Documentation
1. Set up the repository
1. Update package index and install packages to allow HTTPS based repositories
sudo apt-get update sudo apt-get install ca-certificates curl gnupg
2. Add Docker’s official GPG key
sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a + r /etc/apt/keyrings/docker.gpg
3. Set up the repository with the following command
echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu\ "$(. /etc/os-release & amp; & amp; echo "$VERSION_CODENAME")" stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2. Install the Docker engine
1. Update package index
sudo apt-get update
2. Install Docker Engine, containerd and Docker Compose
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3. Verify that the Docker Engine installation was successful by running the image
sudo docker run hello-world
The following indicates that the docker installation is successful
Install docker-compose
1. Update and install
sudo apt-get update sudo apt-get install docker-compose-plugin
2. Verify that the installation is successful
docker compose version
The version number appears to indicate success
3. Set up the Docker Group. In order to use Docker in non-sudo mode, you need to add the current user to the Docker Group.
sudo usermod -aG docker $USER
Set Docker image acceleration
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://XXXXXXXX.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
XXXX above, go to Alibaba Cloud to search: Image Container Service, and then click on the left menu: Image Tool -> Image Accelerator to view
docker compose deployment
1. Prepare docker-compose.yaml
version: "3.7" services: nginx: container_name: "lnmp_nginx" image: nginx:1.24 restart: always ports: - "80:80" - "443:443" #depends_on: # - "php" volumes: - /docker-lnmp/nginx/conf.d:/etc/nginx/conf.d - /docker-lnmp/nginx/log:/var/log/nginx - /www:/usr/share/nginx/html environment: -TZ=Asia/Shanghai - MYSQL_ROOT_PASSWORD=123456 mysql: container_name: "lnmp_mysql" image: mysql:5.7 ports: - "3306:3306" volumes: - /docker-lnmp/mysql/data:/var/lib/mysql - /docker-lnmp/mysql/conf.d:/etc/mysql/conf.d - /docker-lnmp/mysql/log:/var/log/mysql restart: always environment: -TZ=Asia/Shanghai - MYSQL_ROOT_PASSWORD=123456 php: build: context: ./php container_name: "lnmp_php" #image: php:7.4-fpm ports: - "9000:9000" volumes: - /www:/var/www/html - /docker-lnmp/php/phpfile:/usr/local/etc/php - /docker-lnmp/php/phpfile/conf.d:/usr/local/etc/php/conf.d - /docker-lnmp/php/log:/var/log/php restart: always #stdin_open: true #tty: true environment: -TZ=Asia/Shanghai redis: container_name: "lnmp_redis" image: redis:5 ports: - "6379:6379" volumes: #- D:\docker-lnmp\redis\conf:/usr/local/etc/redis - /docker-lnmp/redis/data:/data #- D:\docker-lnmp\redis\log:/var/log/redis restart: always #command: #redis-server /usr/local/etc/redis/redis.conf --requirepass 123456 environment: - TZ=Asia/Shanghai
2. Go to the specified path and execute the following command
docker compose up -d
Encountered an error:
Err:1 http://deb.debian.org/debian bullseye InRelease Could not connect to deb.debian.org:80 (151.101.110.132), connection timed out Err:2 http://deb.debian.org/debian-security bullseye-security InRelease Unable to connect to deb.debian.org:80:
Method 1: Edit the /etc/apt/sources.list file (sudo is required), and add the following entries at the top of the file (please make corresponding backups before operation)
# deb http://snapshot.debian.org/archive/debian/20211220T000000Z bullseye main deb http://deb.debian.org/debian bullseye main # deb http://snapshot.debian.org/archive/debian-security/20211220T000000Z bullseye-security main deb http://security.debian.org/debian-security bullseye-security main # deb http://snapshot.debian.org/archive/debian/20211220T000000Z bullseye-updates main deb http://deb.debian.org/debian bullseye-updates main
Method 2: Refer to https://developer.aliyun.com/mirror/debian to modify and try
Method 3: Execute before build installs the extension
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak & amp; & amp; \ echo "deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib" >/etc/apt/sources.list & amp; & amp; \ echo "deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib" >/etc/apt/sources.list & amp; & amp; \ echo "deb https://mirrors.aliyun.com/debian-security/ bullseye-security main" >/etc/apt/sources.list & amp; & amp; \ echo "deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main" >/etc/apt/sources.list & amp; & amp; \ echo "deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib" >/etc/apt/sources.list & amp; & amp; \ echo "deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib" >/etc/apt/sources.list & amp; & amp; \ echo "deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib" >/etc/apt/sources.list & amp; & amp; \ echo "deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib" >/etc/apt/sources.list
When the IP is entered remotely, a 404 error is found; modify /etc/nginx/conf.d/default.conf to the following; server and container access problems
server { listen 80; listen [::]:80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm index.php ; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /www; } }
You may have problems installing docker with windows
1. The IP of docker on windows is very slow;
Open opcache | Modify the cifs kernel module | Synchronize files directly to docker without using mount
2. Can access HTML, but cannot access PHP, mainly because the server [$document_root] in ngxin fails to parse