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.

Install MySQL using Docker

1
docker run --name my-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=my_database -e MYSQL_USER=my_user -e MYSQL_PASSWORD=my_user_password -v mysql_data:/var/lib/mysql -d mysql:latest
  • -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.

Install PostgreSQL using Docker

1
docker run --name my-postgres -p 5432:5432 -e POSTGRES_PASSWORD=my_pg_password -e POSTGRES_DB=my_pg_database -v pg_data:/var/lib/postgresql/data -d postgres:latest
  • -p 5432:5432:Map port 5432 of the PostgreSQL container to port 5432 of the host.
  • -e POSTGRES_PASSWORD=my_pg_password:Set the PostgreSQL root user password.
  • -e POSTGRES_DB=my_pg_database:Specify a default database.
  • -v pg_data:/var/lib/postgresql/data:Persist the data in the host’s volume so that the data can be stored permanently.

Install nginx using Docker

1
docker run --name my-nginx -p 8080:80 -v /path/to/nginx.conf:/etc/nginx/nginx.conf -v /path/to/static/files:/usr/share/nginx/html -d nginx:latest
  • -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


Total Site Visits:times
This site was created by LinWhite using the Stellar 1.29.1 theme.
All articles on this site, unless otherwise stated, are licensed under the CC BY-NC-SA 4.0 license. Please credit the source when republishing.