iXora Custom Software Development Blog

Read | Practice | Advance

Docker for beginner

Posted by on in Blog
  • Font size: Larger Smaller
  • Hits: 1303
  • 0 Comments

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

 

The way Docker works

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface.

 b2ap3_thumbnail_architecture_20191009-054101_1.png

Installation

Click here and create your own Docker Hub account and download your machine's operating system supported docker and install in your local machine.

 

Check docker version after installation

docker -v

Docker Commands

docker help

 So it will return all docker commands but some usual common docker commands given below - 

Verify your Networks

networetwork ls

Start docker containers 

docker-compose up or docker-composer up -d

Stop and remove our docker container

docker-compose down

Create our Docker image from our Dockerfile

docker build --tag my_http

Show the running containers

docker ps

Stopping a running container

docker stop CONTAINER_ID

Stop all running container

docker container stop $(docker container ls -aq)

Delete all running containers

docker container rm $(docker container ls -aq)

Delete docker image

docker rmi IMAGE_ID

 

Create Docker file

FROM nginx
COPY html /usr/share/nginx/html

 

Create Docker image from the Dockerfile

docker build --tag my_http_server 

 

Check the image has been created

docker images

 

 Run our docker image on port 8080

docker run -d -p 8080:80 --name my_http_server

 

 Check my docker is running?

http://localhost:8080

 

Stop running container 

docker stop CONTAINER_ID

 

Find the running image ID 

docker images 

 

Remove the running image ID

docker rmi my_http

 

If removal fails force the removal

docker rmi my_http –force

 

Create php Docker file and image build from it

Create php Docker file

FROM php:7.2-cli
COPY ./src /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "./docker_index.php" ]

 Create our Docker image from my php Dockerfile

docker build -t run-php 

 Run my docker image which should have copied a local file called docker_index.php

docker run -it --rm --name run-app run-php

 Create php Dockerfile

FROM php:7.2-apache

 Create my docker-compose file

version: "3"
services:
    www:
        build: .
        ports:
            - "8080:80"
        volumes:
            - ./src:/var/www/html/
        networks:
            - default

 Start my docker container from docker-compose file

docker-compose up 
or
docker-compose up - d    // detached mode

 

 

Note: if there is some help needed for install to create docker image then feel free to contact ixora solution. 

 

 

 

Rate this blog entry:
2

Comments

  • No comments made yet. Be the first to submit a comment

Leave your comment

Guest
Guest Monday, 03 August 2020