DEV Community

JPL
JPL

Posted on • Updated on

Docker commands - beginner (part1)

When the user is beginner, in the most of cases it’s not sure how to start with Docker, even just to try it in own environment, like in my case. 🤔

I started to learn about Docker concepts using different courses and one of the first it was on KodeKloud platform with hands-on examples to setup Docker and use commands. ✅

Sometimes they have free week or even month to learn some stuff, so I used promotion to learn Docker basic. 💡

Another useful course was on the platform SimpleLearn, later I discover Nana where you can see hands-on examples. 💡

But…you are watching, writing, learning new things, taking notes.. But ..but I need to try it on my own laptop. So I decided to install Docker and try these simple commands.

Depending on what is your configuration, you need to choose right installation. I need it to install on Ubuntu, but if you don’t have Linux, another option is to try it on AWS (Amazon Web Services) installing Linux on EC2 instance. 🐧 ☁️

EC2 instance is “computer in the cloud”, where you can install Linux and try docker, later user can terminate machine without effecting local machine. Also, AWS have free tier for one year, that mean you can use EC2 instance — Linux machine every month 750h (hours), t2.micro, t3.micro. More information you can find on this link.

Install Docker on Ubuntu

Install Docker on Windows

Install Docker on AWS (EC2 Instance)

After installation and setup Docker on my laptop, I started to try some commands, like pull the image, try it to run, discover some images and containers..

In the one moment, I used command to delete image (docker rmi name_of_image)..But I couldn’t delete it just like that. Why?
I need to research why and how it’s possible to delete image, why error is dependencies… After discovering problem, understand problem and error messages, I need it to write it on medium, so I can use it later like reminder how to resolve and delete image from container. All these commands it’s possible to find using docker help, but these commands are the first things that I tried when I wanted at least pull image, run image, delete, list containers, list images, remove images, containers etc.

Courses and hands-on give you ideas on the beginning what to try, how to try, but when you get problem which is not in the course, you need on own find solution and how to resolve (or ask friend to help you if he/she is better in Docker :D).

I will try also document everything on my GitHub page about Docker, Jenkins and everything how to do it and why I do it just like that.

RUN — the docker run command is used to run a container from an image.

If the image is not downloaded, it will automatically download it. The version of image it will be the latest.

COMMAND: docker run ubuntu cat /etc/release

DOWNLOAD SPECIFIC IMAGE (VERSION)

To download specific image of ubuntu, for example ubuntu 18.04, the command will be:

docker run ubuntu:18.04 /etc/release

/etc/release — will show other details about the image

Numbers of version of ubuntu 18.04 in the Docker world is called TAGS. Official versions of tags for specific image, user can find on the https://hub.docker.com/ .

LIST CONTAINERS: docker ps , docker ps -a

STOP CONTAINER: docker stop name_of_container

REMOVE CONTAINER: docker rm name_of_container

PULL IMAGE: docker pull name_of_image (example: docker pull image ubuntu)

LIST IMAGES ON DOCKER HOST: docker images, docker images -a (all images)

REMOVE IMAGES: docker rmi name_of_image

IMPORTANT: To remove images from Docker host, user need to check that container it’s not running. User need to STOP AND DELETE all dependent containers to be able to delete an image.

Example:

When you want to delete image ubuntu-latest and you get part of error message is “dependencies -container 6a17ef9 “ , user need first remove dependencies of container (6a17..) and then remove image. If you have more errors similar to this, but with different number of container, do it all steps again a), b), c) (optional) .

a) Remove container: docker rm 6a17efd

b) Remove image: docker rmi ubuntu-latest

c) List images to check that is deleted: docker images

Visit article: Intro to Docker

Top comments (0)