cmdref.net - Command Reference

This site is command references for system engineers.

User Tools

Site Tools


Top     SiteMap

Sidebar

Top     SiteMap








Etc


Reference











.

middleware:virtualization:docker:index.html



Middleware

Docker

Web Sites

Install

CentOS

# yum install docker
# systemctl start docker
# systemctl status docker
# systemctl enable docker
# systemctl enable docker.service
# systemctl start docker.service
# docker -v
# docker info


Docker Commands

Commands Note Example
docker search docker search centos
docker images List images
docker pull Pull an image or a repository from a Docker Registry docker pull centos:latest
docker pull centos:centos7
docker pull centos:centos5
docker run Run a command in a new container run -it --name CONTAINERNAME centos /bin/bash
docker rm Remove one or more containers docker rm CONTAINERNAME
docker rmi Remove one or more images docker rmi centos
docker ps List containers docker ps
docker ps -a
docker start Start a container docker start CONTAINERNAME
docker stop Stop a container docker stop CONTAINERNAME
docker attach Attach to a running container docker attach CONTAINERNAME
docker commit Create a new image from a container's changes docker commit 03db8562c742 centos:centos7


man docker

NAME
       docker - Docker image and container command line interface

SYNOPSIS
       docker [OPTIONS] COMMAND [arg...]

       docker daemon [--help|...]

       docker [--help|-v|--version]

OPTIONS
       --help
         Print usage statement

COMMANDS
       attach
         Attach to a running container
         See docker-attach(1) for full documentation on the attach command.

man docker-run

NAME
       docker-run - Run a command in a new container

OPTIONS
       -d, --detach=true|false
          Detached mode: run the container in the background and print the new container ID. The default is false.


Example

Install docker image

# docker pull  centos:latest        <- About 70MB
# docker images
# docker run -it --name centos7_test1 centos /bin/bash

# Ctrl+d   <- For exit and finish docker
or
# Ctrl+p + Ctrl+q   <- For exit but not finish dokcer

# docker ps -a

How to use static IP address.

# docker network create --subnet=192.168.10.0/24 test_nw
# docker network ls
# docker network inspect test_nw

# docker run -it --name test --net=test_nw --ip=192.168.10.100 -d centos:centos6 /bin/bash

run the container in the background

# docker run --privileged -d -p 80:80 --name httpd fnya/apache /sbin/init
    -d : Detached mode: run the container in the background and print the new container ID.

# docker exec -it httpd /bin/bash

[root@centos7 ~]# systemctl enable httpd.service
[root@centos7 ~]# systemctl start httpd.service
[root@centos7 ~]# exit

# curl -s http://localhost/ | head -n 1
# docker images
# docker stop  XXXXXX


Network

Check Docker Network

# brctl show
# ifconfig docker0

Container with Bridge

# docker network create --driver bridge --subnet=192.168.0.0/24 --gateway=192.168.0.1 --opt "com.docker.network.bridge.name"="docker1" my-network
# docker network inspect my-network    <- check my-network
# docker run --name container1 --net my-network --ip 192.168.33.11 -dt centos


Storage

How to use Host OS's Volume

# docker run -i -t -v /var/volume:/root centos /bin/bash

/var/vlume is host OS's volume.
/root is container's volume.


Data Volume Container

How to create Data Volume Container

# docker run -d --name data -v /root centos /bin/bash



middleware/virtualization/docker/index.html.txt ยท Last modified: 2017/05/06 by admin