How to create an image and a container for Docker
This article introduces the knowledge of "how to create an image and a container in Docker". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Create a mirror
1. Here is a handwritten Dockerfile document
2. Transfer the Dockerfile file to / usr/redis
3. Then you need to customize the network type
Since the default network cannot set a fixed address, we will create a custom network and specify the network segment: 172.10.0.01and16
Docker network create-subnet=172.10.0.0/16 mynetwork
Delete Custom Network
Docker network rm mynetwork is fine.
If you can't remember the command, then use docker network help directly.
4. Create an image
Docker build-t redis1.
Pay attention to a dot in the back.
5. View the created image
Docker images
Create a container
1. Create a container
Docker run-itd-- name redis-kaka-p 6384 name redis-kaka 6379-ip 127.10.0.4 redis1
Parameter explanation:
Redis-kaka: container name
Redis1: image name
-d: runs the container in the background and returns the container ID
-I: runs the container in interactive mode, usually in conjunction with-t
-p: Port mapping, format: host (host) port: container port
-t: reassign a pseudo-input terminal to the container, usually used in conjunction with-I
-- ip: make a fixed ip for the container
-- net: specifies the network mode
2. View the container
Docker ps-a\ docker container ls
3. Enter the container
Docker exec-it redis-kaka bash
That's all for "how to create an image and a container for Docker". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!