ubuntu:docker:basic_usage_of_docker
Differences
This shows you the differences between two versions of the page.
ubuntu:docker:basic_usage_of_docker [2019/11/27 00:54] – created peter | ubuntu:docker:basic_usage_of_docker [2020/04/16 08:04] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Docker - Basic Usage of Docker ====== | ||
- | |||
- | Commonly used options of the docker command. E.g. how to download a docker image, build a container and how to access the container. | ||
- | |||
- | To create a new container, you should start by choosing a base image with the OS, e.g. ubuntu or centos or another. You can search for a base image with the docker search command: | ||
- | |||
- | <code bash> | ||
- | docker search ubuntu | ||
- | </ | ||
- | |||
- | This command will show you all ubuntu images. You can try by yourself docker search centos etc. | ||
- | |||
- | Download the base image to our server, use the command: | ||
- | |||
- | <code bash> | ||
- | docker pull ubuntu | ||
- | </ | ||
- | |||
- | |||
- | The docker pull imagename command will download an image to your server from docker registry/ | ||
- | |||
- | Now you can see all downloaded images by using the command: | ||
- | |||
- | <code bash> | ||
- | docker images | ||
- | </ | ||
- | |||
- | |||
- | The Ubuntu image was downloaded from DockerHub/ | ||
- | |||
- | To create the container, you can use docker create or docker run. | ||
- | |||
- | <code bash> | ||
- | docker create ubuntu: | ||
- | </ | ||
- | |||
- | |||
- | **docker create** command will create a new container but not start it. So now you can use run command: | ||
- | |||
- | <code bash> | ||
- | docker run -i -t ubuntu: | ||
- | </ | ||
- | |||
- | This command will create and run a container based in ubuntu 16.04 image and run a command /bin/bash inside the container, you will be automatically inside the container after running the command. | ||
- | |||
- | |||
- | The container will stop when you leave it with the command exit. If you like to have a container that is running in the background, you just need to add the -d option in the command. | ||
- | |||
- | <code bash> | ||
- | docker run -i -t -d ubuntu: | ||
- | |||
- | /bin/sh -c "while true; do echo hello world; sleep 1; done" this is bash script to echo "hello word" forever. | ||
- | </ | ||
- | |||
- | Now you can see the container running in the background by using command: | ||
- | |||
- | <code bash> | ||
- | docker ps | ||
- | </ | ||
- | |||
- | or if you want to see the logs result from that bash command you can use the command: | ||
- | |||
- | <code bash> | ||
- | docker logs NAMES/ | ||
- | </ | ||
- | |||
- | |||
- | How can I access the shell of container that runs in the background mode? This command will connect you to the shell of the container: | ||
- | |||
- | <code bash> | ||
- | docker exec -i -t NAMES/ | ||
- | </ | ||
- | |||
- | |||
- | You can see the hostname and the container ID are equal, this means that you are inside of the container shell. When you type `exit` on that shell you will leave that shell but the container is still running. | ||
- | |||
- | Another command that you will use often is: | ||
- | |||
- | <code bash> | ||
- | docker stop NAME/ | ||
- | </ | ||
- | |||
- | This will stop the container without deleting it, so you can start it again with the command: | ||
- | |||
- | <code bash> | ||
- | docker start NAME/ | ||
- | </ | ||
- | |||
- | If you like to remove the container, stop it first and then remove it with the command: | ||
- | |||
- | <code bash> | ||
- | docker rm NAME/ | ||
- | </ | ||
- | |||
- | This is just a short introduction on the installation and basic usage of Docker on Ubuntu, you can find the detailed Docker documentation page here. | ||
- | |||
- | An in-depth introduction to Docker is available in this Howtoforge tutorial series: https:// | ||
- | |||
- | ---- | ||
- | |||
- | ===== Conclusion ===== | ||
- | |||
- | Docker is an open source container virtualization platform which helps developers to deploy their applications and system administrators to manage applications in a safe virtual container environment. Docker runs on the Intel / AMD 64-bit architecture and the kernel should be higher 3.10 version. With Docker, you can build and run your application inside a container and then move your containers to other machines running docker without any worries. | ||
- | |||
- | ---- | ||
- | |||
- | ===== References ===== | ||
- | |||
- | https:// | ||
ubuntu/docker/basic_usage_of_docker.1574816063.txt.gz · Last modified: 2020/07/15 09:30 (external edit)