What is the docker

The last article described the basic operation of docker pull image, create start container, so there is a question, if you need to operate mysql, nginx configuration, there are two ways.

  • usedocker execIt’s the simplest and most straightforward thing to command into the container and do what you want.
  • Another approach is to use external mount, which is essentially to do a file or folder mapping, which maps the host machine to the files or folders inside the container once, so that what we do outside the container can be mapped directly inside the container to do what we want to do.

Docker mount command

  • Use the -v command when starting the container, which should be made clear by an example.

    $ docker run -d -p 6379:6379 \ 
    	--name redis \ 
    	-v $PWD/docker/redis/redis.conf:/etc/redis/redis.conf \
    	-v $PWD/docker/redis/data:/data \
        redis:latest redis-server /etc/redis/redis.conf \
        --requirepass "123456" --appendonly yes
    Copy the code
  • Parameter explanation:

    -d: starts the container in daemon mode

    –name: names the container

    -p 6379:6379: maps port 6379 of a container to port 6379 of a host

    – v $PWD/docker/redis/redis conf: / etc/redis/redis conf: Will host in the current directory of the redis. Conf mapped to the start of the redis configuration file – v $PWD/docker/redis/data: / data: the host in the current directory/docker reids/data/data mounted to the container

    Redis :latest: specifies a mirror

    Redis-server /etc/redis/redis.conf: Specifies the configuration file to start the redis-server process

    –requirepass “123456” : specifies the password for the link to redis-server. –appendonly yes: enables data persistence

  • Conf, data files, and folders outside the container will be directly applied to the corresponding files inside the container.

Other common mounts

  • mysql

    Docker run - d - ring = true \ # set into the container internal permissions are root - name mysql5.7 -p 3306: \ 3306 - v/my/mysql/datadir: / var/lib/mysql \  -v /my/mysql/conf.d:/etc/mysql/conf.d \ -v /my/mysql/my.cnf:/etc/mysql/my.cnf \ -e MYSQL_ROOT_PASSWORD=yourpassword \ Mysql :5.7Copy the code
  • nginx

    docker run --name mynginx -d -p 80:80 \
    -v /nginx/html:/usr/share/nginx/html \
    -v /nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
    -v /nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
    -v /nginx/logs:/var/log/nginx \
    nginx
    Copy the code