Skip to content

Instantly share code, notes, and snippets.

@linuxoracledev
Created January 6, 2020 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxoracledev/5035360a53d686778774907330850d18 to your computer and use it in GitHub Desktop.
Save linuxoracledev/5035360a53d686778774907330850d18 to your computer and use it in GitHub Desktop.
How To Install and Use Docker on Ubuntu 18.04
#Update your existing list of packages
sudo apt update
#Install a few prerequisite packages
sudo apt install apt-transport-https ca-certificates curl software-properties-common
#Add the GPG key for the official Docker repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#Add the Docker repository to APT sources
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
# Update the package database
sudo apt update
#Make sure to install from the Docker repo instead of the default Ubuntu repo
apt-cache policy docker-ce
#Install Docker
sudo apt install docker-ce
#Check Status
sudo systemctl status docker
#Add your username to the docker group
sudo usermod -aG docker ${USER}
#To apply the new group membership
su - ${USER}
#Confirm that your user is now added to the docker group
id -nG
#Add a user to the docker group
# sudo usermod -aG docker username
#Using the Docker Command
#docker [option] [command] [arguments]
#To view all available subcommands
docker
#To view the options available to a specific command
docker docker-subcommand --help
#To view system-wide information about Docker
docker info
#Search for images(ubuntu) available on Docker Hub
docker search ubuntu
#Download the official ubuntu image
docker pull ubuntu
#To see the images that have been downloaded
docker images
#Run a container using the latest image of Ubuntu. (-it switches gives interactive shell access into the container)
docker run -it ubuntu
#Update the package database inside the container
apt update
#Then install any application in it
apt install nodejs
#verify that Node.js is installed
node -v
#Any changes ymade inside the container only apply to that container
#To exit the container,
exit
##Managing Docker Containers
#To view the active containers
docker ps
#To view all containers — active and inactive
docker ps -a
#To view the latest container
docker ps -l
#Start a specific container
docker start d9b100f2f636
#Stop a specific container
docker stop d9b100f2f636
#Remove a specific container
docker rm d9b100f2f636
#Commit the changes to a new Docker image instance
#docker commit -m "Commit Message" -a "Author Name" container_id repository/new_image_nam
docker commit -m "added Node.js" -a "sammy" d9b100f2f636 sammy/ubuntu-nodejs
#Lsting the Docker images again
docker images
#Pushing Docker Images to a Docker Repository
#log into Docker Hub.
docker login -u docker-registry-username
#tag your image with your registry username.
docker tag sammy/ubuntu-nodejs docker-registry-username/ubuntu-nodejs
#push your own image using:
#docker push docker-registry-username/docker-image-name
docker push sammy/ubuntu-nodejs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment