That is to add in the dockers-compose.yml file build
to specify the path of my Dockerfile file
. For example, my dockers-compose.yml file is in the docker-compose folder, and the docker-compose folder is in the Dockerfile and the war package of the project. The same level directory, that is, the Dockerfile file, is at the upper level of the dockers-compose.yml file,
then specify context: ../
and dockerfile: Dockerfile
The above ../
is the meaning of the upper level directory, which Dockerfile
is the name of the Dockerfile file .
Look at the dockers-compose.yml file
version: '3.1'
services:
mysql:
restart: always
build:
context: ../ # 指定dockerfile文件的所在路径
dockerfile: Dockerfile # 指定Dockerfile文件名称
image: ssm:1.0.1 #自定义镜像名和版本号
container_name: ssm
ports:
- 8080:8080
environment:
TZ: Asia/Shanghai
To write the Dockerfile file, note that there is no suffix
look at the location
Drag and drop all into Xterm:
Create a new docker_ssm folder in the /opt directory
mv
The command moves all docker-compose, Dockerfile, and ssm.war to the /opt/docker_ssm directory,
then cd
to the docker-compose folder,
and then docker-compose up -d
executes the command
and press Enter. The result is as follows:
WARNING warning means:
you can directly start the docker-based Compose.yml and the custom image built by the Dockerfile file, use the following command:
docker-compose up -d
If the image customized using the Dockerfile file does not exist, it will help us build a custom image. If the custom image already exists, it will run the custom image directly.
If we want to rebuild, enter the following command
rebuild custom image
docker-compose build
If you want to rebuild before running the container, enter the following command
docker-compose up -d --build
ERROR error means:
In the docker environment, after configuring the docker-compose.yml configuration file, before running the container, mysql image has been started in my docker container, and the port 8080 has been occupied. When starting It will report an error. Enter the following command:
docker stop 容器id
, just close mysql
database
The import and export of the database is the same as before
Then you can visit
http://192.168.10.8:8080/ssm/ in the browser