Docker

docker build -t mibu/jitsi-meet<new image name> .

docker commit 82669bca3013<container ID> avinash/jitsi-meet<image name>

docker system df
docker system df -v
docker network ls

docker network rm f7a386c67223

docker network create –gateway=192.168.40.4 –subnet=192.168.0.0/16 jitsi_bridge
docker run –net jitsi_bridge –ip 192.168.90.95 -itd shailesh/jitsi-meet

Rename image after pull
docker tag local/old_image local/new_imagename

Push image in dockerhub
docker push docker_id/image
e.g.
docker push shailesh/image_name

NOTE: docker_id should match with the docker hub’s id
Image name should be format docker_id/image_name
You should be logged in to docker hub from terminal

Useful docker commands

  • docker build -t [image name] .
  • docker images -a
  • docker ps -a
  • docker run [image name]
  • docker run -d –name [container name] [image name]
  • docker run -v [/host/directory]:[/container/directory] [image name]
  • docker start [container name]
  • docker exec -it [container name] /bin/bash
  • docker rmi [image name]
  • docker rm [container name]
  • docker inspect [container_name]
    to get ip address
  • docker search [image name]
    to search image on docker hub and list whether it is official or not

Sample Docker File

FROM php:7.0-apache  
COPY [source directory] /var/www/html
EXPOSE 80

NOTE:

  • Keep the name of file Dockerfile only
  • Keep the source project directory in the same level where Dockerfile file is present

 

How to create docker image

  1. Create Docker file: Dockerfile
    FROM php:7.0-apache
    COPY src/ /var/www/html
    EXPOSE 80
  2. docker build -t image-filename docker-file-location
    docker build -t hello-world .
  3. sudo docker run -p localpot:imageport image-name
    sudo docker run -p 8989:80 image-name

    To name container
    sudo docker run -p 8980:80 –name=customcontainername image

    To mount local app with image/container
    sudo docker run -p 8980:80 -v /var/www/html/localapp/:/var/www/html -i -t php-app

    To copy files from host to docker container
    sudo docker cp ./test.php container:/var/www/html/

    To start existing container
    sudo docker start[container name|container id]

    To stop existing container
    sudo docker stop [container name|container id]

    To login to container bash
    sudo docker exec -it –user root mydockercontainer /bin/bash

How to export and import image

You will need to save the docker image as a tar file:

docker save -o <path for generated tar file> <image name>

Then copy your image to a new system with regular file transfer tools such as cp or scp. After that you will have to load the image into docker:

docker load -i <path to image tar file>

PS: You may need to sudo all commands.

Ref: Link: https://stackoverflow.com/questions/23935141/how-to-copy-docker-images-from-one-host-to-another-without-via-repository


How to remove container and images

Docker ps -a               # Lists containers (and tells you which images they are spun from)
Docker images              # Lists images  
Docker rm <container_id>   # Removes a container

Docker rmi <image_id>      # Removes an image 
                           # Will fail if there is a running instance of that image i.e. container

Docker rmi -f <image_id>   # Forces removal of image even if it is referenced in multiple repositories, 
                           # i.e. same image id given multiple names/tags 
                           # Will still fail if there is a docker container referencing image

Ref Link: https://stackoverflow.com/questions/33907835/docker-error-cannot-delete-docker-container-conflict-unable-to-remove-reposito




docker composer commands

  1. check docker composer version
    docker-compose -v
    docker-composer version
  2. create docker composer file at any locationvim docker-composer.yml

    version: ‘3’services:
    web:
    image: nginx
    ports:
    –  9090:80database:
    image: redis
  3. compile the docker-compose yml file
    docker-compose config

  4. run/up docker-compose
    docker-compose up -d
  5. check running container
    docker ps
  6. stop/down docker-compose
    docker-compose down
  7. help manual
    docker-compose –help
  8. scaling containers
    docker-compose up -d –scale service-name=count
    e.g. docker-compose up -d –scale database=4

create docker image from container

  1. create base container
    docker create –name custom_container_name -p 8080:80 image_name
  2. list available images
    docker images
  3. list available containers
    docker ps -a
  4. start the container
    docker start custom_container_name
  5. modify the running container
    docker cp local_files_or_directory custom_container_name:/var/www/html/
  6. create image from modified container
    docker commit custom_container_name
    list images
    docker images
    There must be a new image without tag name
  7. tag the untitled image
    docker tag [image id] new_image_name
    list images
    docker images
    You will find new image you’ve just created
  8. commit with tag name [optional]
    docker commit custom_container_name new_image_name
  9. remove the temporary created container
    docker ps
    docker stop custom_container_name
    docker rm custom_container_name
  10. run the newly created image
    docker ps -a
    docker run –name custom_container_name -d -p 8080:80 newly_created_image_name
  11. check browser
    http://localhost:8080

Ref: https://www.scalyr.com/blog/create-docker-image/