Experiment with Docker
Start/stop a container
-
Start a container with a never ending command in a shell
docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
-
Check the status of the container
docker ps
-
Stop the container
docker stop REPLACE_WITH_NAME_OF_THE_CONTAINER
-
Start the container again
docker start REPLACE_WITH_NAME_OF_THE_CONTAINER
Bind history
-
Concatenate history of commands inside container and outside container
docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash
Launch a web server
- Run a web server inside a docker container in foreground
docker run nginx
- Alternatively, run a web server inside a detached container (in the background)
docker run -d nginx
- Get the port number used for the container
docker inspect REPLACE_WITH_NAME_OF_THE_CONTAINER
- Open a browser and test the web server
http://localhost:REPLACE_WITH_APPROPRIATE_PORT_NUMBER
Launch glassfish
- Run glassfish inside a docker container
- First get a glassfish image (latest by default)
docker search glassfish docker pull glassfish
- Check the glassfish image is now available
docker images
- Launch a container with the glassfish image in interactive mode
docker run -t -i glassfish /bin/bash
- Stop this container (CTRL C)
- First get a glassfish image (latest by default)
- Map a host file space with a path in the container
- Launch a container with the glassfish image and map a host file space with a path in the container
docker run -t -i -v /PUT_THE_PATH_TO_YOUR_DIRECTORY_HERE:/usr/local/mydir glassfish /bin/bash
- Launch a container with the glassfish image and map a host file space with a path in the container