Assignment: Manage Multiple Containers
- related
- Docker Mastery
Assignment
- Run a
nginx
, amysql
, and ahttpd
(apache) server - Run all of them
--detach
(or-d
), name them with--name
nginx
should listen on80:80
, httpd on8080:80
, mysql on3306:3306
- When running
mysql
, use the--env
option (or-e
) to pass inMYSQL_RANDOM_ROOT_PASSWORD=yes
- Use
docker container logs
on mysql to find the random password it created on startup - Clean it all up with docker container stop and docker container rm (both can accept multiple names or ID’s)
- Use
docker container ls
to ensure everything is correct before and after
Answers
# Run nginx container
docker container run --name nginx -p 80:80 -d nginx
# Run mysql container
docker container run --name mysql -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes -d mysql
# Run httpd container
docker container run --name httpd -p 8080:80 -d httpd
Retrieve the mysql’s random root password
docker container logs mysql | grep "ROOT PASSWORD"
Check containers status
docker container ls
Stop all running containers
docker container stop nginx mysql httpd
Remove containers
docker container rm nginx mysql httpd