Installing Common Development Environments with Docker (MySQL, Redis, etc.)
In daily development, the installation and configuration of service software such as MySQL and Redis is essential. Using Docker can not only quickly deploy these software, but also avoid the problem of inconsistent configuration environment. This article will introduce how to install and run common development software through Docker, including but not limited to MySQL, Redis, MongoDB, etc.
-p 3306:3306: Maps the MySQL container’s port 3306 to the host’s port 3306.
-e MYSQL_ROOT_PASSWORD=my-secret-pw: Sets the root user password for MySQL.
-e MYSQL_DATABASE=my_database: Creates a database named my_database upon startup.
-e MYSQL_USER=my_user and -e MYSQL_PASSWORD=my_user_password: Creates a new user and password for the application.
-v mysql_data:/var/lib/mysql: Uses a Docker volume to persist the MySQL data directory on the host, ensuring that data is not lost when the container stops.
Install Redis using Docker
1
docker run --name my-redis -p 6379:6379 -d redis:latest
-p 6379:6379:Map the Redis container’s port 6379 to the host’s port 6379.
Install MongoDB using Docker
1
docker run --name my-mongo -p 27017:27017 -v mongo_data:/data/db -d mongo:latest
-p 27017:27017:Map port 27017 of the MongoDB container to port 27017 of the host.
-v mongo_data:/data/db:Use the data volume mongo_data to persist data to ensure that the data is retained after the container is stopped.
-p 8080:80:Map the container’s port 80 to the host’s port 8080 so that it can be accessed through http://localhost:8080.
-v /path/to/nginx.conf:/etc/nginx/nginx.conf:Mount the host’s nginx configuration file into the container to implement custom configuration.
-v /path/to/static/files:/usr/share/nginx/html:Mount the host’s static file directory to nginx’s HTML directory to host static websites or resources.
If you have any questions, feel free to leave a comment so we can discuss and learn together If you found this article helpful, please respond with an emoji, leave a comment, or share it with more friends Thank you