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
- Create Docker file: Dockerfile
FROM php:7.0-apache
COPY src/ /var/www/html
EXPOSE 80 - docker build -t image-filename docker-file-location docker build -t hello-world .
- 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
- check docker composer version
docker-compose -v
docker-composer version
- create docker composer file at any locationvim docker-composer.yml
version: ‘3’services:
web:
image: nginx
ports:
– 9090:80database:
image: redis
- compile the docker-compose yml file
docker-compose config
- run/up docker-compose
docker-compose up -d - check running container
docker ps - stop/down docker-compose
docker-compose down - help manual
docker-compose –help - scaling containers
docker-compose up -d –scale service-name=count
e.g. docker-compose up -d –scale database=4
create docker image from container
- create base container
docker create –name custom_container_name -p 8080:80 image_name - list available images
docker images - list available containers
docker ps -a - start the container
docker start custom_container_name - modify the running container
docker cp local_files_or_directory custom_container_name:/var/www/html/ - create image from modified container
list imagesdocker commit custom_container_nameThere must be a new image without tag namedocker images - tag the untitled image
list imagesdocker tag [image id] new_image_nameYou will find new image you’ve just createddocker images - commit with tag name [optional]
docker commit custom_container_name new_image_name - remove the temporary created container
docker ps
docker stop custom_container_name
docker rm custom_container_name
- run the newly created image
docker ps -a
docker run –name custom_container_name -d -p 8080:80 newly_created_image_name - check browser
http://localhost:8080
Ref: https://www.scalyr.com/blog/create-docker-image/