Tikejhya: Ashish Nepal

Knowledgebase

Category: docker

private docker registry

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Private docker registry using letsencrypt and Authentication.

#Creating letsencrypt:

./letsencrypt-auto certonly -a manual --rsa-key-size 4096 -d www.tikejhya.com -d registry.tikejhya.com --debug

#Creating auth file

docker run --entrypoint htpasswd registry:2 -Bbn testuser testpassword > auth/htpasswd

 

#If required:

docker stop registry && docker rm -v registry

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#Create registry
docker run -d -p 443:5000 --restart=always --name registry \
-v `pwd`/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v `pwd`/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/mydomain_public.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/mydomain_private.key \
registry:2

#Test login
docker login registry.tikejhya.com

#Pull some image
docker pull php:php-fpm
#Tag image into newly created registry

docker tag registry.tikejhya.com/my-php

#push image to repo

docker push registry.tikejhya.com/my-php

#Lets pull from remote server:

docker login registry.tikejhya.com
docker --config ~/.docker pull registry.tikejhya.com/php-fpm

docker pull registry.tikejhya.com/bmi-php

docker basics

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#How to install Docker in centos or similar flavours
yum install docker-io

#Lets start service now
service docker start

#ensure its in boot
chkconfig docker on

#Explore other commands
docker help

# Pull image from docker repository
docker pull centos

# Lets run bash from container.
docker run -i -t centos /bin/bash

#Show me current running docker containers
docker ps

#Show me all container
docker ps -a

#show me latest container
docker ps -l

#Attach to detached container using container ID
docker attach c3852139b652

#List currently running docker images.
[root@173 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
fe4fa1ab8f74 centos "/bin/bash" 2 days ago Up 2 days
serene_turing
990c4b7837c7 centos "/bin/bash" 4 days ago Up 4 days
silly_cray

# Get ip address of most recent docker image
[root@173 ~]# docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)

172.17.0.2

#Show all images (any status)
[root@173 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe4fa1ab8f74 centos "/bin/bash" 2 days ago Exited (137) 5 minutes ago serene_turing

#Attach certain images using Names

[root@173 ~]# docker start -ai serene_turing

#How to detach docker mode:
Ctrl+p, Ctrl+q

#Start docker container with network using hosts
#This is used as workaround with the issue of centos 6.7
$ docker run -d --net=host -it centos /bin/bash

#Install sshd inside container
$ docker exec -it fe4fa1ab8f74 yum -y install openssh

Problems:
docker cp /etc/ssh/sshd_config serene_turing:/etc/ssh/sshd_config
Error: Path not specified

#Docker CP from host to container is only available from 1.8 onwards

Workaround
$ cat /local/file/path | docker exec -i sh -c 'cat > /inside/docker/file/path'

#Lets see the copied file:
docker exec -it fe4fa1ab8f74 cat /etc/ssh/sshd_config

#How to commit change of container into new container
docker commit fe4fa1ab8f74 tikejhya/base_image:version1

#Docker run and exit
docker run -d tikejhya/base_image:version1

#How to start docker with /bin/bash using IMAGEVersion
docker run -d --net=host -it tikejhya/base_image:version1 /bin/bash

#How to run centos docker container
docker run -i -t centos /bin/bash

#How to expose port 80 and 443 of host machine to guest machine
docker run -i -p80:80 -p443:443 -t nginx /bin/bash

#How to rename docker existing container
docker rename 95f08c928a66 web1_tikejhya_nginx

#Show me latest container
#-l, –latest=false Show the latest created container, include non-running
#-q, –quiet=false Only display numeric IDs
docker ps -q -l

# Resolution inside docker
vi /etc/init.d/docker
DOCKER_OPTS=" --dns 172.25.0.56"

#Docker run forward port Image/name:tag
docker run -p80:80 -p443:443 -t tikejhya/base_image_web1_tikejhya_nginx:version1 /bin/bas

### delete docker images that was on status exited weeks ago
docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

#To expose just one port, this is what you need to do:
docker run -p :

#To expose multiple ports, simply provide multiple -p arguments:
docker run -p : -p :

#pull mysql image from
$ docker pull mysql
#Docker run -name provide some name with mysql root password using latest image
[root@173 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mysql latest 6f8e95fd9237 3 days ago 400.1 MB

$ docker run –name db1.ashishnepal -e MYSQL_ROOT_PASSWORD=mynewpassword -d mysql:latest

# docker exec db1.ashishnepal mysql -V
$ mysql Ver 14.14 Distrib 5.7.17, for Linux (x86_64) using EditLine wrapper

[root@173 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest ae324ca2b946 3 days ago 181.6 MB
mysql latest 6f8e95fd9237 3 days ago 400.1 MB

$ docker run –name web1.ashishnepal –link db1.ashishnepal:mysql -d nginx

[root@173 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f40cadc4b463 nginx “nginx -g ‘daemon of 7 seconds ago Up 6 seconds 80/tcp, 443/tcp web1.ashishnepal
3f366e92bd38 mysql:latest “docker-entrypoint.s 2 days ago Up 2 days 3306/tcp db1.ashishnepal

Powered by WordPress & Theme by Anders Norén