Download the imageWrite a Dockerfile
After writing the Dockerfile, put the Dockerfile in the root directory of the web program and upload it to the server.
The CD was uploaded to the catalogue just uploaded.
Run the Docker command here: docker build -t <要生成的镜像的名称> . (Note, there is a dot at the end, this point is the path of the Dockerfile, because the Dockerfile is now in the current directory, so just hit a dot, the image name after the -t parameter does not need to be <>)
For example:
In the last step, we made the image, now we put the image in Docker and let it run.
Run the Docker command: docker run -d --rm -p 5000:80 -<实例名称>-name <镜像名称>
-d will output the unique identifier of the image after successful startup, --rm will determine that if there is an instance with the same name, it will be deleted and replaced -p Specify the program running port Host port: container port Note: Because EXPOSE is not specified above, the port of the container is 80 --name parameter After the instance name and image name do not need to be <>
I specified port 5002 of the server to port 80 of the container, and now accessing 5002 will access the DEMO program
docker ps to see all the instances that have been deployed
The instance deployed by the above command will be automatically uninstalled after the container restart or server restart, which means that once the Docker service or image is restarted, the instance will no longer exist, and Docker needs to be re-runn, as shown in the figure below, the instance deployed just now is gone after restarting the service
Automatic deployment after restart Use this command: docker run -d --restart=always -p 5002:80 --name <实例名> <镜像名> Note: --restart and --rm conflict, only one can be selected
As shown in the figure below, using the --restart=always parameter will not affect the instance
Use Nginx for reverse proxies
Open the configuration file and change the configuration within the Server node
After the configuration, execute the command nginx -t in liunx, which will detect whether the nginx configuration file is wrong
If the detection passes, execute nginx -s reload, which will update the configuration file and use it immediately
After execution, access the domain name you just bound, and use the domain name to successfully access the instance that was previously published to port 5002 using Docker.
|