How to setup Docker Desktop on Ubuntu

How to setup Docker Desktop on Ubuntu

simple and easy to understand notes by Aman Reddy

How to Install Docker Desktop on Ubuntu

  1. Download Docker Desktop .deb Package file From docs.docker.com/desktop
  2. For non-Gnome Desktop environments, gnome-terminal must be installed : sudo apt install gnome-terminal
  3. Update Packages and dependancies using : sudo apt-get update
  4. Install Downloaded docker desktop .deb file using : sudo apt-get install ./docker-desktop.deb
  5. Launch Docker Desktop using : sudo systemctl --user start docker-desktop
  6. Check docker version using : docker --version

How to Create or build Custom Ubuntu docker Image

  1. Create Directory : mkdir directory_name
  2. Create file name -> Dockerfile with below content

FROM ubuntu:latest

# Set the root password using passwd (optional if you want security replace user_password & set your own password)

RUN echo 'root:user_password' | chpasswd

# Install sudo (if you want)

RUN apt-get update && apt-get install -y sudo

# Create a non-root user (if you want to create non root user replace user_name & set your username)

RUN useradd -m -s /bin/bash user_name

# Set a password for the non root user (optional)

RUN echo 'user_name:user_password' | chpasswd

# Customize the PS1 prompt for the user

RUN echo 'PS1="user_name@user_name:~ "' >> /home/user_name/.bashrc

# Set the user as the default user for the container

USER dockeradmin

CMD ["bash"]

3. save this file with name Dockerfile without any extention

4. Build this custom image using :

sudo docker build -t DockerHub_User_name/Repository_Name:tag

Note : The -t flag in the docker build command is used to specify a name and optionally a tag for the image being built.

docker build : used to build a Docker image from a Dockerfile.

-t : Tags the image with a name for better understanding.

DockerHub_User_name/Repository_Name:tag : This specifies the name and tag for the Docker image you're building ( Note : The tag is optional. If you specify it, it helps with versioning )

5. Run a container based on your image :

sudo docker run -it --name YourContainer_Name dockerHub_username/Repository_Name:Tag

Note :

docker run : used to create and start a new container from a Docker image.

-i : Runs the container in interactive mode.

-t : interact with the container via a terminal interface.

--name YourContainer_Name : Assigns a name to the container for better understanding.

Tag : An optional tag for the image, usually indicating a version. If no tag is specified, Docker uses the latest tag by default.

6. for stop running container :

sudo docker stop Container_ID

7. if you exited from the Running container you need to start first this container using :

sudo docker start Container_ID

and For Running the existing Container using

sudo docker exec -it Container_Name or Container_ID /bin/bash

8. if you have install or deploy your project or any dependancis you need to save this before push this image to dockerhub without saving or commit you didnt get your installtion when you pull later for doing this job use below command :

sudo docker commit Container_ID DockerHub_Username/Repository_Name:Tag

9. if you want to push image to DockerHub use below :

sudo docker push DockerHub_UserName/DockerHub_Repository_Name:Tag

10. if you want to pull image from DockerHub use below :

docker pull DockerHub_UserName/DockerHub_Repository_Name:Tag

11. For checking All Docker Images :

sudo docker images -a

12. For checking All Docker Running Container :

sudo docker ps -a

13. For delete Docker Container :

First check Container is Running or not using

sudo docker ps -a

Next Stop Running Container using

sudo docker stop Container_ID

Delete Docker Container using

sudo docker rm Container_ID

if you want to delete docker image

sudo docker rmi -f Image_ID

14. For Checking Docker Container IP use below :

sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' Container_ID or Name

15. For Checking status, Start,restart,stop Docker :

sudo systemctl status docker

sudo systemctl start docker

sudo systemctl restart docker

sudo systemctl stop docker


if you have any query contact Aman Reddy


要查看或添加评论,请登录

Aman Reddy的更多文章

社区洞察

其他会员也浏览了