Docker first basic practical to run container and create an image
For demo launch redhat linux OS from AWS
Install docker in VM
#yum install docker -y
Start Docker and Grant Access
A very common mistake that many beginners do is, After they install docker using the sudo access, they miss the step to Start the Docker daemon and grant acess to the user they want to use to interact with docker and run docker commands.
Always ensure the docker daemon is up and running.
A easy way to verify your Docker installation is by running the below command
#docker run hello-world
If the output says:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
This can mean two things,
Docker deamon is not running.
Your user does not have access to run docker commands.
Start Docker daemon
If you notice that the docker daemon is not running, you can start the daemon using the below command
sudo systemctl start docker
Grant Access to your user to run docker commands
if you run docker run hello-world
you will face an below error
To grant access to your user to run the docker command, you should add the user to the Docker Linux group. Docker group is create by default when docker is installed.
create user, here I have created user called "ash" and added user in group called "Docker"
Docker is Installed, up and running 🥳🥳
switch to the "ash" user (your created user in above step)
Use the below command , to verify that docker is up and running.
docker run hello-world
Great Job, Now start with the examples folder to write your first Dockerfile and move to the next example.
Clone this repository and move to example folder
git clone https://github.com/iam-veeramalla/Docker-Zero-to-Hero
cd examples
Login to Docker [Create an account with https://hub.docker.com/]
docker login
Build your first Docker Image
You need to change the username accoringly in the below command
docker build -t ashwini0246/my-first-docker-image .
Check docker images
docker images
Run your First Docker Container
docker run -t ashwini0246/my-first-docker-image
Push the Image to DockerHub and share it with the world
docker push ashwini0246/my-first-docker-image
Output of a command will be
Once it runs successfully, you will see image in Docker hub
Subscribe to my newsletter
Read articles from ashwini purwat directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by