This is the 25th day of my participation in the August Challenge
If ❤️ my article is helpful, welcome to like, follow. This is the biggest encouragement for me to continue my technical creation. More previous articles in my personal column
Docker-composer usage practices
Dockerfile allows users to manage a separate application container; Docker-composer allows users to define a set of associated application containers (called a project) in a template (YAML format)
For example, a Web service container plus a database service container on the back end
Creating a File Directory
ghost
- ghost
- Dockfile
- nginx
- nginx.conf
- Dockfile
- data
- docker-compose.yml
Copy the code
Docker – composer. Yaml formats
ghost-app:
build:ghost
depends_on:
- db
ports:
- "2368:2368"
nginx:
build:nginx
ports:
- "80:80"
depends_on:
- ghost-app
db:
image: "Mysql: 5.7.15"
Copy the code
Configuration ghost Dockerfile
FROM ghost
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
CMD ["npm", "start", "--production"]
Copy the code
config.js
nginx Dockerfile
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
Copy the code
nginx.conf
worker processes 4; events {worker connections 1024; } http { server { listen 80; location / { proxy pass http://ghost-app:2368; }}}Copy the code
ghost docker-compare.yaml
The database-related configurations must be consistent with those in config.js. Db. volumes: $PWD/data:/var/lib/mysql
Ghost directory:
Docke-compose up -d: docke-compose up -d: docke-compose up -d: docke-compose up -d: docke-compose up -d: docke-compose up -d: docke-compose up -d: docke-compose up -d: docke-compose up
Error 502 Bad Gateway is displayed
Indicates that nginx is started, but the link between nginx and ghost-app is incorrect.
Check:
- docker-compose.yaml
- nginx.conf
Docker-compose stop 2 Docker-compose RM 3: Docker-compose rm 3: docker-compose RM 3: Docker-compose RM Docker-compose build 4: docker-compose build 4: docker-compose build 4: docker-compose build 4: docker-compose build 4: docker-compose build 4: docker-compose build 4: docker-compose build Start the container docker-compose up -d 5 with the image. Docker-compose: docker-compose: docker-compose: docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose Access localhost/ghost/setup/one is configuredCopy the code
Localhost /ghost/ Editor/Write an article and publish it, and you can see the published article in localhost.