After installing docker on xubuntu, next you need to learn how to use it, if you are a beginner or new to docker this short tutorial should be able to guide you through the basic of using docker.
First of all, docker is a command line tool, so you'll be working with command line all the time. In this tutorial i'm not going through all of the commands, this tutorial just covering the basic command so that you can get started with docker quickly.
1. Getting docker version
To show which docker version that you have on your computer, you can run the docker version command, like this:docker version
2. Downloading docker images
When working with docker, you need to get the specific images that you need, for example if you want to have a web server then you need to download docker images for nginx or apache. You can find list of docker images on docker hub, to download docker image you can use docker pull command.
docker pull [image-name]
Example:
docker pull nginx
docker pull mysql
docker pull ubuntu
3. Checking list of docker images
After you download the docker image, you can check list of docker images that currently on your computer using docker images command.
docker images
4. Run the container based on the image
To run docker image into a container, you can use the docker run command, this command have some parameters that you can add, such as -it for interactive mode, -h for hostname, -p for port and so on, for now let's just do the basic.
docker run [parameters] [image-name]
Example:
docker run -it ubuntu
docker run -it hello-world
docker run -it debian
Note: you can also run container in the background by adding -d parameterTry this:
- run docker container for nginx
docker run -it -p 8282:80 nginx
http://localhost:8282
5. Checking active docker container
You can check list of active docker container by using docker ps command like this:
docker ps
The command above will only shows active or currently running containers, if you want to show all containers including the one that's not active, simply add -a parameters.
docker ps -a
6. Start, stop and restart container
You can use docker start to start inactive container, docker stop to stop a running container and docker restart to restart a container.
docker start [container-id]
docker stop [container-id]
docker restart [container-id]
Note: you can find container id by running the docker ps command.
I think this covers all of the basic of docker commands, sure there are lot more to learn, but at least we cover the basic here, and in my opinion the best way to learn something is by doing it, so keep on practicing guys and see you in the next tutorial.