How to create, start, stop and delete the Docker containers ?

Create docker container with Ubuntu Image

Note: To create docker container, you need to make sure docker is installed on your machine by following “How to install Docker on Ubuntu 18.04 ?”

$ sudo docker create ubuntu:18.04

Once, you see docker container is installed, you can see its container id as,

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
49db5136dac8        ubuntu:18.04        "/bin/bash"         5 seconds ago       Created                                 distracted_hamilton

Note: for all below commands “CONTAINER ID” is required, in our case the container id is “49db5136dac8” as can be seen above, please change it to your container id.

Login to docker container shell

To login to docker container, we need to make sure we are running the docker, you can run the docker in background as,

$ sudo docker run -it  -d "ubuntu:18.04"

above command will run the docker in background and then you can access the shell as,

$ sudo docker exec -i -t 49db5136dac8 bash

Start the docker container

$ sudo docker start 49db5136dac8
49db5136dac8

once you start the container, you can see the same in “ps” command as,

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
49db5136dac8        ubuntu:18.04        "/bin/bash"         8 minutes ago       Up 8 minutes                            distracted_hamilton

Stop the docker container

$ sudo docker stop 49db5136dac8
49db5136dac8

Delete the docker container

$ sudo docker rm CONTAINER ID

here, you can check which are the all containers available on your machine using,

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
49db5136dac8        56def654ec22        "/bin/bash"         15 minutes ago      Exited (0) 6 minutes ago                        distracted_hamilton
97f8cfdb23d8        56def654ec22        "/bin/bash"         17 minutes ago      Exited (0) 15 minutes ago                       angry_ishizaka
218a9b8c69ef        a4a181159e32        "/bin/bash"         2 hours ago         Exited (0) 19 minutes ago                       trusting_franklin

so, here we have 3 containers, of which if we want to delete “49db5136dac8” , we can use the command as,

$ sudo docker rm 49db5136dac8

How to install docker on ubuntu AWS... x
How to install docker on ubuntu AWS Server

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux