Giter VIP home page Giter VIP logo

docker_test's Introduction

Docker build: docker build -t php_test .

To Run the container: docker run -p 8080:80 php_test

Here 8080 is localhost post 80 exposed port of container. You can browse http://localhost:8080 or http://172.17.0.2

docker run -it tagname bash (for bash access)

Docker with shared volume

docker run -it --mount type=bind,source=/var/www/html/docker_test,target=/var/www/html --env-file=env_file php_test

Docker Multiple environment variables with -e (mutiple files also same)

docker run -t -e MYSQL_HOST='172.17.0.03' \

-e MYSQL_USER='root'
-e MYSQL_PWD='root'
-e MYSQL_DB='docker_test'
php_test

Docker access local DB

(in linux type ip addr show and look for the docker0 ip). it will be 172.17.0.1

Some docker commands in hand

docker build https://github.com/docker/rootfs.git#container:docker

Here container is tag/branch. docker is subdirectory

docker build -f <file_path_or_name>

docker build -f ubuntu_php/php_small_docker -t php_small_docker .

docker run --rm -it -p 192.168.99.100:3000:3000 docker-react

--rm Automatically remove the container when it exits

--interactive , -i Keep STDIN open even if not attached

--tty , -t Allocate a pseudo-TTY

-d runs as dameon (runs in background)

docker-machine ip default -- gets the virtual machine ip address of machine 'default'

docker ps => list containers

docker ps -a => list all container

docker ps -q => only numerical id's

docker ps -l => Show the latest created container (includes all states)

docker-machine ip default docker run --rm -it -p 192.168.99.100:3000:3000 react-demo

//remove containers docker rm -f $(docker ps -aq)

--force , -f Force the removal of a running container (uses SIGKILL)

//images docker rmi -f $(docker images -aq)

--all , -a Show all images (default hides intermediate images) --quiet , -q Only show numeric IDs

images -> layers -> containers class -> inheritance -> instance

nginx - daemon off; nginx to run frontend in containers

docker run -it tagname bash

List all containers (only IDs) docker ps -aq

Stop all running containers docker stop $(docker ps -aq)

Remove all containers docker rm $(docker ps -aq)

Remove all images docker rmi $(docker images -q)

// to remove all running containers docker-compose stop

docker container stop $(docker ps -aq)

docker container rm $(docker ps -aq)

remove all images

docker rmi $(docker images -q)

$ docker build -t test-pid . $ docker run -it -d --name t-pid test-pid

--name Assign a name to the container

Now let's run a shell to access the container:

$ docker exec -it t-pid sh

The docker exec command runs a new command in a running container.

Docker inspect

docker inspect <container-name/id>

will tell you all details. even you can grep for your desired results like Ip address

docker compose

docker-compose up docker-compose build <image_name_from_yml) docker-compose stop docker-compose down [-v]

Docker system prune - remove unused data

docker system prune

Ubuntu go thru the commands mentioned here

Add the docker group if it doesn't already exist:

sudo groupadd docker Add the connected user "$USER" to the docker group. Change the user name to match your preferred user if you do not want to use your current user:

sudo gpasswd -a $USER docker Either do a newgrp docker or log out/in to activate the changes to groups. sudo setfacl -m user:$USER:rw /var/run/docker.sock

shared volume ubuntu

docker run -d -v /home/santosh/docker_test/ubuntu_php:/var/www/html -it -p 9999:80 php_small -d for dameon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.