1. Before you start | Before getting start
Docker official website Get started learning records, Chinese are self-translated, uncalibration, original website: docs.docker.com/get-started…
Prerequisites:
1. Install docker Desktop Application and complete the Welcome Guide in application
2. If you have a GitHub account, you can create a Git remote repository
Concept of 3.
– Image: indicates an Image file
Image provides an isolated filesystem to run a container. It contains everything to run an app, including all dependcies, configurations, scripts, binaries, environmental viriables default command to run and other metadata.
The Image file provides an isolated system for the container to run.
– Container: indicates a Container
A process on your machine that has been isolated from all other process on host.
From the Image file, you can generate a running container instance/container file.
2. Proofing | Sample application
get the app
Download: github.com/docker/gett…
(Record: app directory command line pull download failed, return to app git repo click compress package download)
Json ‘file and’ SRC ‘ ‘spec’ directories.
build the app’s container image
Create a ‘Dockerfile’ file in the same directory as’ package.json ‘with the following contents
# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
Copy the code
Enter the following command in the app directory
docker build -t getting-started .
Copy the code
‘docker build’ : Build image file from Dockerfile
‘-t’ : parameter -t flag Specifies (tag) the geting-started label
‘. ‘: The dot at the end indicates looking for Dockerfile in the current directory
start an app container
1. Run the ‘docker run’ command to run the image file with the specified name
docker run -dp 3000:3000 getting-started
Copy the code
‘-d’ : Run container in detached mode (background) flag to run the container in detached mode
‘-p’ : map port flag
Single Flag can be combined, so -d and -p can be combined to form -dp
‘300:3000’ : Create a map to map port 3000 of container/Container to port 3000 of host/host
2. Obtain sample of port localhost 3000 as shown in the following figure
3. You can add items by yourself
4. You can view the image file in use and the Container running on the Docker Desktop
Review | recap
Learned:
– build container image
– create a Dockerfile
– start the container and see the running app from localhost
The next step:
– change the app
– Run the application with a new image
3. Update application | Update the application
Update the source code | update the source code
1. Update the code in ‘SRC /static/js/app.js’
- <p className="text-center">No items yet! Add one above! </p> + <p className="text-center">You have no todo items yet! Add one above! </p>Copy the code
2. Build the image file of the updated version
docker build -t getting-started .
Copy the code
3. Start a new container
docker run -dp 3000:3000 getting-started
Copy the code
4. Then… An error has occurred!
The reason is that the new container cannot start while the old one is still running. The container can only process one process on the machine when using port 3000
The solution: Remove the old containers
Remove the old container | replace the old container
Terminate the Container before removing it.
There are two ways to remove it: using the Command Line Interface (CLI) or using the Docker Dashboard.
1. Remove the Container on the CLI
‘docker PS’ : Get the CONTAINER ID
2. After obtaining the CONTAINER ID, stop running the container with the specified ID
# Swap out <the-container-id> with the ID from docker ps
docker stop <the-container-id>
Copy the code
The container named Peaceful_Elbakyan with ID 35C7440C0ED7 has been terminated
You can also see ⬇️ from the Docker Dashboard
3. Remove after termination
docker rm <the-container-id>
Copy the code
These actions can also be done by clicking the icon in the Docker Dashboard
Start the updated app container | start the updated app container
Once deleted, you can re-run the ‘docker run’ command to start the updated container
docker run -dp 3000:3000 getting-started
Copy the code
Port 3000 Is displayed as follows
Review | recap
The next step:
– The container is expected to retain the original entry after the update is started
– Want to see the updated code without rebuilding and start