Docker Modifies the configuration file

The binding operation has been performed during run

Docker run [OPTIONS] IMAGE [COMMAND] [ARG…]

  1. -p: specifies the port mapping. The format is host (host) port: container port
  2. –volume, -v: Binds a data volume
  3. -d: Runs the container in the background and returns the container ID.
  4. –name=”redis”: specify a name for the container;
  5. -e username=” Ritchie “: Set the environment variable.
  6. -m: sets the maximum memory used by a container.
  7. Redis-server –appendonly YES: Run the redis-server startup command in the container and open the Redis persistent configuration
docker run -p 6378:6379 --name redis -v /Users/conf/docker/redis/conf/redis.conf:/etc/redis/redis.conf  -v /Users/conf/docker/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
Copy the code

Start a container in backend mode, map port 80 of the container to port 80 of the host, and map the directory /root/dock/nginx /data of the host to /data of the container.

docker run -p 80:80 -v /root/docker/nginx/data:/data -d nginx:latest
Copy the code

Modify an unbound configuration file

Inspect docker inspect redis

You can use this in conjunction with grep, for example to look at just the container IP

docker exec -it reids ls /usr/local/bin

Copy the file inside and outside the container operation into the container, add the file we want to modify cptest.txt

Docker cp redis:/test/cptest.txt./Copy the code

Docker cp cptest.txt docker cp cptest.txt redis:testCopy the code

In addition to cp operations, we can also operate externally on other files in the container

Modify external ports

Docker inspect redis | grep Id CD/var/lib/docker CD/containers container Id vim hostconfig. JsonCopy the code

Why go to/var/lib/docker/containers /…

Because in the inspect content you can see that the host information is stored here