0% found this document useful (0 votes)
7 views

Docker Commands

Uploaded by

patilsiddeshb16
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Docker Commands

Uploaded by

patilsiddeshb16
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Docker commands

Steps for Installing Docker on Ubuntu:

1. Open the terminal on Ubuntu.

2. Remove any Docker files that are running in the system, using the following command:

$ sudo apt-get remove docker docker-engine docker.io

After entering the above command, you will need to enter the password of the root and press
enter.

3. Check if the system is up-to-date using the following command:

$ sudo apt-get update

4. Install Docker using the following command:

$ sudo apt install docker.io

You’ll then get a prompt asking you to choose between y/n - choose y

5. Install all the dependency packages using the following command:

$ sudo snap install docker

docker --version – it gives the current version of docker

Pull an image from the Docker hub using the following command:

$ sudo docker run hello-world


Check if the docker image has been pulled and is present in your system using the following
command:

$ sudo docker images

To display all the containers pulled, use the following command:

$ sudo docker ps -a

To check for containers in a running state, use the following command:

$ sudo docker ps
docker search -

docker pull –
Docker run -it -d name

This command is used to create a container from an image

docker ps -a

This command is used to show all the running and exited containers

docker exec

Usage: docker exec -it <container id> bash

This command is used to access the running container

docker stop

Usage: docker stop <container id>

This command stops a running container


docker kill

Usage: docker kill <container id>

This command kills the container by stopping its execution immediately. The difference between
‘docker kill’ and ‘docker stop’ is that ‘docker stop’ gives the container time to shutdown gracefully, in
situations when it is taking too much time for getting the container to stop, one can opt to kill it

To kill a container you must have a container running so first create a container.
BUILD AN IMAGE USING DOCKER

Step 2: Create an HTML application or use an existing template and Place your HTML files and
any other necessary assets (e.g., CSS, JavaScript, images) in the same project directory.

Step 3: Create a docker file and Copy Files to the Docker Image:

Add instructions in your Dockerfile to copy the HTML files into the Docker image. You can use the
COPY instruction. For example

Step 4: Build the Docker Image:

Run the following command to build the Docker image, giving it a name and optional tag:
Step 5: Run the Docker Container:

Once the image is built, you can run a container from it using the following command:

Tag the Docker Image:

Tag the Docker image to include your Docker Hub username and repository name. Replace
<username> and <repository> with your actual Docker Hub username and repository name:

docker tag my-html-app <username>/<repository>


Step 6: Access Your HTML Application:

Open a web browser and go to http://localhost:1002 (or the host and port you specified) to
access your HTML application running inside the Docker container.

Step 7: Log in to Docker Hub:

If you're not already logged in to Docker Hub, use the docker login command to log in to your
Docker Hub account:
Step 8: Push the Docker Image to Docker Hub:

Now, push the Docker image to Docker Hub using the following command. Replace
<username> and <repository> with your actual Docker Hub username and repository name:
docker push <username>/<repository>

You might also like