Skip to content

harish-repo/docker-help

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Docker commands

Show Commands

Docker version

$ docker version

Show info like number of containers, etc

$ docker info

Working with containers

About Containers

Docker containers are often compared to virtual machines but they are actually just processes running on your host os. In Windows/Mac, Docker runs in a mini-VM so to see the processes you will need to connect directly to that. On Linux run "ps aux" and see the processes directly.

Create and run a container in foreground

$ docker container run -it -p 80:80 nginx

Create and run a container in background

$ docker container run -d -p 80:80 nginx

Naming Containers

$ docker container run -d -p 80:80 --name nginx-server nginx
  • Looked for image called nginx in image cache
  • If not found in cache, it looks to the default image repo on Dockerhub
  • Pulled it down (latest version), stored in the image cache
  • Started it in a new container
  • We specified to take port 80- on the host and forward to port 80 on the container
  • We can specify versions like "nginx:1.09"

List running Containers

$ docker container ls

List all Containers (includes not running)

$ docker container ls -a

Stop Container

$ docker container stop <ID>

Stop all running Containers

$ docker stop $(docker ps -aq)

Remove Container

can't remove running containers, must stop first
$ docker container rm <ID>

Remove running Container forcefully

$ docker container rm -f <ID>

Remove multiple Containers

$ docker container rm <ID> <ID> <ID>

Remove all Container

$ docker rm $(docker ps -aq)

Get logs

use name or ID
$ docker container logs <NAME>

List processes running in Container

$ docker container top <NAME>

Image Commands

About Images
  • Images are app bianaries and dependencies with meta data about the image data and how to run the image
  • Images are no a complete OS. No kernel, kernel modules (drivers)
  • Host provides the kernel, big difference between VM

List images pulled

$ docker image ls

Pull an image

$ docker pull <image>

Remove an image

$ docker image rm <image>

Remove all images

$ docker rmi $(docker images -a -q)

Sample container creation

NGINX:

$ docker container run -d -p 80:80 --name nginx nginx (-p 80:80 is optional as it runs on 80 by default)

APACHE:

$ docker container run -d -p 8080:80 --name apache httpd

MONGODB:

$ docker container run -d -p 27017:27017 --name mongo mongo

MYSQL:

$ docker container run -d -p 3306:3306 --name mysql --env MYSQL_ROOT_PASSWORD=123456 mysql

Container info

View info on container

$ docker container inspect <NAME>

View Specific property (--format)

$ docker container inspect --format '{{ .NetworkSettings.IPAddress }}' <NAME>

View Performance stats (cpu, mem, network, disk, etc)

$ docker container stats <NAME>

Accessing Container

Create new nginx container and bash into

$ docker container run -it --name <NAME> nginx bash
  • i = interactive Keep STDIN open if not attached
  • t = tty - Open prompt

Run/Create Ubuntu container

$ docker container run -it --name ubuntu ubuntu

(no bash because ubuntu uses bash by default)

You can also make it so when you exit the container does not stay by using the -rm flag

$ docker container run --rm -it --name <NAME> ubuntu

Access an already created container, start with -ai

$ docker container start -ai ubuntu

Use exec to edit config, etc

$ docker container exec -it mysql bash

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published