Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Tutorials»How to Create, List & Delete Docker Containers on Linux

    How to Create, List & Delete Docker Containers on Linux

    RahulBy RahulMarch 7, 20162 Mins ReadUpdated:March 29, 2017

    In our previous tutorials you have learned about installation of Docker engine on CentOS/RHEL and Ubuntu operating system and pulled images from Docker hub. After that created containers with images. This tutorial will help you to create, list & delete docker containers on Linux machine.

    #1. Launch Docker Container

    To launch a new Docker container using below command. This will start a new container and provide you access to that container with /bin/bash shell.

    # docker run [OPTIONS] <IMAGE NAME> [COMMAND] [ARG...]
    

    For example below command will create new docker container using the image named “ubuntu”. To list all available images use docker images command.

    # docker run -i -t ubuntu /bin/bash
    

    To exit from docker container type CTRL + P + Q. This will leave container running in background an provide you host system console. If you used exit command, it will stop the current container. Click here to read for more options about docker run command.

    #2. List Docker Containers

    After existing from Docker container, execute below command to list all running containers.

    # docker ps
    
    CONTAINER ID     IMAGE     COMMAND        CREATED        STATUS        PORTS    NAMES
    f2582758af13     ubuntu    "/bin/bash"    2 hours ago    Up 2 hours             first_ubuntu
    

    By default Above command will list only running containers. To list all containers (including stopped container) use following command.

    # docker ps -a
    
    CONTAINER ID   IMAGE   COMMAND        CREATED        STATUS        PORTS    NAMES
    f2582758af13   ubuntu  "/bin/bash"    2 hours ago    Up 2 hours             first_ubuntu
    6b5b5a969241   centos  "/bin/bash"    2 days ago     Exited (0) 24 hours ago   ubuntu-web
    

    #3. Start/Stop/Attach Container

    You can start, stop or attach to any containers with following commands. To start container use following command.

    # docker start <CONTAINER ID|NAME>
    

    To stop container use following command.

    # docker stop <CONTAINER ID|NAME>
    

    To attach to currently running container use following command.

    # docker attach <CONTAINER ID|NAME>
    

    #4. Drop Docker Container

    Before deleting any container make sure that container is stopped. You can use ‘docker ps -a’ command to list status of containers. If container is still running first stop that container using given commands in above step.

    Now use the following command to delete single or multiple containers.

    # docker rm <CONTAINER ID|NAME> <CONTAINER ID|NAME>
    

    You can also delete all stopped containers at once using the following command.

    # docker rm $(docker ps -a -q)
    
    Docker Docker Containers
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Search, Pull, List & Delete Docker Images on Linux
    Next Article Magento 2 Database Configuration File

    Related Posts

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How To Enable SSH Server on Ubuntu 22.04

    Updated:April 22, 20222 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    10 Best Linux Video Players in 2022

    Updated:February 18, 20226 Mins Read

    How to Switch Python Version in Ubuntu & Debian

    Updated:April 22, 20223 Mins Read

    3 Comments

    1. Maulik Shah on May 11, 2017 5:25 am

      Hi I want to drop Docker container which is Up since last 2 days .. Can you guide how to do ?

      Reply
    2. Ferri on March 8, 2016 2:10 pm

      hi do you have information where i can try docker for free and online? since my laptop still 32 bit and docker doesnt support old architecture 🙁

      i really want to learn about docker things ..

      Reply
      • Sunil Raskar on June 4, 2018 12:33 am

        Hi FERRI,
        YES, you can learn docker for free. Here are the simple steps that you can follow to begin your journey.

        1. Open an AWS account. You will need a credit card. There will be no charges for 12 months if you really take efforts to understand and use the free service.
        2. Launch Ubuntu EC2 16.04 instance.
        3. Use an SSH terminal using a client software like MobaXterm.
        4. Install docker user docker . You will find tons of docker beginner tutorial on line. Happy learning…

        Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.