MacOsx Docker Start and Stop

docker-start:

#!/usr/bin/env bash

case $1 in
  -h|--help)
    echo $'usage: docker-start\n\nStarts Docker (Docker.app) on macOS and waits until the Docker environment is initialized.'
    exit 0
    ;;
esac
(( $# )) && { echo "ARGUMENT ERROR: Unexpected argument(s) specified. Use -h for help." >&2; exit 2; }

[[ $(uname) == 'Darwin' ]] || { echo "This function only runs on macOS." >&2; exit 2; }

echo "-- Starting Docker.app, if necessary..."

open -g -a Docker.app || exit

# Wait for the server to start up, if applicable.  
i=0
while ! docker system info &>/dev/null; do
  (( i++ == 0 )) && printf %s '-- Waiting for Docker to finish starting up...' || printf '.'
  sleep 1
done
(( i )) && printf '\n'

echo "-- Docker is ready."

docker-stop:

#!/usr/bin/env bash

case $1 in
  -h|--help)
    echo $'usage: docker-stop\n\nStops Docker (Docker.app) on macOS.'    
    exit 0
    ;;
esac
(( $# )) && { echo "ARGUMENT ERROR: Unexpected argument(s) specified. Use -h for help." >&2; exit 2; }

[[ $(uname) == 'Darwin' ]] || { echo "This function only runs on macOS." >&2; exit 2; }

echo "-- Quitting Docker.app, if running..."

osascript - <<'EOF' || exit
tell application "Docker"
  if it is running then quit it
end tell
EOF

echo "-- Docker is stopped."
echo "Caveat: Restarting it too quickly can cause errors."

Advertisements

Setting up Docker Private Registry

create a folder which name is docker-private-registry

then install docker compose

pip install docker-compose

then create the docker-compose.yml

registry:
image: registry
environment:
– STORAGE_PATH=/registry
volumes:
– registry-stuff:/registry
ports:
– “5000:5000”

run the compose file with

docker-compose up

then you will see the blank page when you visit http://localhost:5000

private registry is done but i found the nice ui for registry

 

How To Dockerize Jenkins

create a sample directory  with mkdir jenkinsci and create a new Dockerfile

cd jenkinsci

touch Dockerfile

 

FROM jenkins:2.0

USER root
RUN apt-get update \
&& apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*
RUN echo “jenkins ALL=NOPASSWD: ALL” >> /etc/sudoers

USER jenkins
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt

then create a plugins.txt file for jenkins plugins

scm-api:latest
git-client:latest
git:latest
greenballs:latest

save it then build the jenkins image

sudo docker build -t jenkinsci .

now we must to run container

sudo docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker -p 8080:8080 jenkinsci

by the way we mapped docker socket ,binary  for running docker commands in container

this command will return container job id. Dont clear the console!

when you visit the http://localhost:8080 you will see the jenkins default login screen

 

you can find the administator password with

docker logs <job_id>

———————————————————————————————————————-

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

67120601cc394ff697b8a23e30440288


You can continue the next steps then you will see the Jenkins Home screen, then we must the test docker command with docker-test project

  • Create a Freestyle Project
  • Add shell build step then save it
  • sudo docker run hello-world

  • Run the build and look at the build logs

run the build.

 

Well, you dockerized jenkins 🙂 awesome!  In next chapter we will integrate jenkins volume

 

 

Docker – 07- Container Networking,IPAddress,Port

docker-turtles-banner-network-copy

Docker Container Networking,IPAddress,Port

Firstly we will create the web server

docker run -d –publish-all jpetazzo/web

Ports

0.0.0.0:32758:8000   -> Port Mapping

:32768-> Host Port Number

:8000-> Containers Port Number

curl localhost:32768

Get the Host Port number by container number

docker port <container_id> 8000

You can assign manually port

docker run -d -p 88:8000 jpetazzo/web

You can get the container  private ip address

docker inspect –format ‘{{.NetworkSettings.IPAdress}}’ <container_id>

Docker – 04- Some Docker Commands

large_v-trans

Some Docker Commands

docker ps -q  > running containers

docker ps -a > all containers

docker ps -aq > all containers id

docker rm <container_id> remove the docker container

docker rmi <image_id> remove docker image

docker rmi  -f <image_id> remove docker image force

docker kill <conainer_id> kill the container

docker stop <container_id> stop the process

docker tag <image_id> myimage > give the name of image

docker ps -l > latest created container

docker images > list of images

You can hit the docker you will see all of command  and if you want to see detail the command docker images -help  

Docker – 03- Building Docker Images (Interactively)

docker-image

We can build docker image with commit

  1. We create container with base ubuntu image

docker run -it ubuntu bash

apt-get install wget

apt-get install curl

docker ps -l

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80a2df5a4a68 ubuntu:latest “bash” 4 minutes ago

You must be see created container id  and we can see diff before and last state

docker diff 80a2df5a4a68

We are commit changes to container

docker commit 80a2df5a4a68

And its give to us new container ID

390bfd8d4b35

docker run -it 390 bash

And you can check curl and wget theese must be installed to new container

We can set the tag name created image with image id or  we can set when creating

docker commit d09e4ad2912b myimage

docker tag d09e4ad2912b myimage

docker images

You must see

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
myimage latest d09e4ad2912b 2 minutes ago