This notebook came from an Ubuntu 18.10 Docker installation. It mixes installation, repository troubleshooting, everyday CLI inspection, and complete removal; those operations have very different effects.
The recorded installation
# Uninstall old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
# Install docker
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose -y
# Config for run docker without sudo
sudo adduser $USER docker
sudo reboot now
# or just logout for effect using command: pkill -u $USER
docker run hello-world
The source adds the user to the Docker group and includes reboot/logout commands. Those are host-level changes, not prerequisites for reading this article.
The codename workaround
Ubuntu 18.10 called cosmic
Ubuntu 18.04 called bionic
[arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
sudo nano /etc/apt/sources.list
#update to:
[arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
The old note replaced cosmic with bionic after a repository failure. Substituting another release’s repository is not a general compatibility solution. Use Docker’s Ubuntu installation reference for a supported host.
The CLI reference
# Login: create new account at hub.docker.com
docker login
## List Docker CLI commands
docker
docker container --help
## Display Docker version and info
docker --version
docker version
docker info
## Execute Docker image
docker run hello-world
## List Docker images
docker image ls
## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq
## To remove container, first get the name from “NAMES” column (docker container ls --all)
docker rm <container_name>
## To remove image, first get the image id from “IMAGE ID” column (docker image ls)
docker rmi <image_id>
## List all running containers
docker ps
## List all created containers (including stopped containers) (only IDs)
docker ps -aq
## Stop all running containers
docker stop $(docker ps -aq)
## View log of container
docker logs <container id>
## Attach ssh to running container
docker exec -i -t $CONTAINER_ID bash -l
## Connect to a running Docker container
docker attach $INSTANCE_NAME
where $INSTANCE_NAME get from: docker ps -a
## Start a stopped container
docker start $INSTANCE_NAME
## View details of a Docker container, including details of mounted folders
docker inspect $INSTANCE_NAME
# View all data volume
docker volume ls
# Delete Persistent Volumes
docker volume rm volumeid
This list includes both inspection and mutation, including volume removal. Inspecting a container is not equivalent to deleting its persistent data.
Historical removal sequence
sudo service docker stop
sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli containerd runc
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce docker-ce-cli containerd runc
sudo rm -rf /var/lib/docker /etc/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock
# Check docker process again
dpkg -l | grep -i docker
The final sequence deletes Docker state and configuration. It is retained as an explicitly destructive historical record, not a routine troubleshooting step. No package, container, volume, or host setting was changed for this revision.