Posts

Showing posts from May, 2017

Simple Docker build example

Example of simple docker build and run This blog shows a very simple example of build a docker image and serve as http server using python. This also covers the concepts of environment variable, volumes and installing packages in building the docker image. Create Files Create the following two files with the contents below: Dockerfile ######################## FROM ubuntu:latest # Install python3 RUN apt-get update RUN apt-get install -y python3 # Set default values for environment variables ENV PORT 8080 # Copy Default Content COPY . /var/www/ # Change to working directory WORKDIR /var/www/ # Expose Ports EXPOSE $PORT # Run Http Server CMD python3 -m http.server $PORT ######################## sample-file.txt My Sample Content..... Build the image docker build --pull -t example/python-http-server:latest -f Dockerfile . Run the image as container docker run --rm -it --name my-python-http-server -p "808...

Docker Compose Hybrid

Docker Compose Hybrid (build + image) The following blog shows example of a hybrid docker-compose file which build an image and also runs a side container Create file "my-docker-compose-hybrid.yml" with the following contents ################ version: '2' networks:   main: services:   my-python-simplehttpserver:     container_name: my-python-simplehttpserver     build: ./python-simplehttpserver     ports:       - "9080:8080"     volumes:       - .:/var/www/     networks:       main:         aliases:           - my-python-simplehttpserver   my-mongo:     container_name: my-mongo     image: "mongo:3.2"     ports:       - "27017:27017"     networks:       main:         aliases:  ...

Docker Compose Basics

Running multiple containers using docker-compose Create my-docker-compose.yml  file  with the following contents: ################ version: '2' networks:   main: services:   my-postgres:     container_name: my-postgres     image: "postgres:9.4.8"     ports:       - "5432:5432"     environment:       - "POSTGRES_USER=myuser"       - "POSTGRES_PASSWORD=superpassword"     networks:       main:         aliases:           - my-postgres   my-mongo:     container_name: my-mongo     image: "mongo:3.2"     ports:       - "27017:27017"     networks:       main:         aliases:           - my-mongo ################ Pull the images docker-...

Git Basic Commands

Git Basic Commands Clone a repository git clone https://gitlab.com/someuser/my-test-repo.git Configure repository Set user.name git config user.name "someuser" Set user.email git config user.email some.user@example.org Set pull.rebase git config pull.rebase false Set push.default git config push.default simple Set credential cache For Unix/Linux Cache for 600 seconds git config credential.helper ‘cache --timeout=600’ For Mac OSX git config credential.helper osxkeychain For Windows git config credential.helper wincred Set core.longpaths (for windows) git config core.longpaths true Set http and https proxy git config http.proxy http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 git config https.proxy http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 Get http and https proxy git config --get http.proxy git config --get https.proxy Unset http and https proxy git config --unset http.proxy git config -...

Docker Client Basics

Docker Client Basics Run a bash shell in temporary Ubuntu Container and install packages docker pull ubuntu:latest docker run -it --rm --entrypoint=/bin/bash ubuntu:latest apt-get update apt-get install curl -y exit Run a bash shell in already started container docker run --name ubuntu-latest -it --rm --entrypoint=/bin/bash ubuntu:latest docker exec -it ubuntu-latest /bin/bash Passing environment variable from host system to docker container Passing a value as environment variable docker run -it --rm --env MY_VALUE=123456 --entrypoint=/bin/bash ubuntu:latest Passing an environment variable which is already defined in the host system docker run -it --rm --env MY_VALUE --entrypoint=/bin/bash ubuntu:latest Attach a host directory to a docker container Using absolute path docker run -it --rm -v /host/machine/sourcecode:/docker_container/sourcecode_directory --entrypoint=/bin/bash ubuntu:latest Using relative path from current d...

Curl Basics

Curl Basics for testing Http Execute GET curl -X GET " https://www.example.org/ " Execute GET with encoded query parameters curl -X GET -G " https://www.example.org/ " --data-urlencode "query1=foo+bar" --data-urlencode "query2=my&special" --data-urlencode "query2=second&value" Execute POST curl -X POST " https://www.example.org/ " Ignore SSL Error curl --insecure -X GET " https://www.example.org/ " Use Http Proxy curl -X POST " https://www.example.org/ " --proxy "http[s]://[user:password@]proxyhost[:port]" Latency / Response time curl -X GET "https://www.example.org/" -s -o /dev/null -w 'Establish Connection: %{time_connect}s\nReceive First Byte: %{time_starttransfer}s\nTotal: %{time_total}s\n' Timeouts curl --max-time 5.5 --connect-timeout 2.5 "https://example.org/" --max-time is the total time to be spent in seconds --conne...