Docker¶
- alawys start by this command to start the defaul machine
docker-machine start default
- Resource: Brad Traversy Help
General¶
- if your using
docker virtualboxmake sure you open virtualbox and the machine is working while you are using thecmd - you will not find your server on
http://localhost:portor0.0.0.0:port. you will find it onhttp://192.168.99.100:port docker imagesare like environments. ex: node.jsdocker containersare your own projects that are built on a specific image.- when you create a container, if the image is not preveously downloaded on your machine it’s going to be downloaded from
docker hub. docker container run <-d | -it> -p <our_local_port>:<virtual_port_for_this_image> <image>docker volumeis a way to pull a continer into your local file system and start editing it.
commands¶
docker version: show docker versiondocker info: show server and client infodocker container run -it -p 80:80 <nginx>: create and run and publish docker container of enginx server on port 80 \(default\) in the foreground.docker container run -d -p 8080:80 --name <container_name> <image>: create and run a container in the backgrounddocker container < ls | ps >: list all running containers.docker container ls -a: list all containers wether they are running or notdocker container rm <container_id>: delete a container with the id of :container_id from your system.docker images: list all images on your machinedocker pull <image_name> : download the <image_name> fromdocker hub`docker stop <container_id>: stop a running container.docker ps: list all running containers.docker container run -d -p 3306:3306 --name <my_name> --env MYSQL_ROOT_PASSWORD=<pass> mysql: create mysql container withenvvariables which ispassword.docker container rm <contaier_name | container_id> -f: remove a running container.docker container exec -it mynginx bash: open the container file system interactively into bash command line- create a volume and grap the files into your local machine
docker container run -d -p 8080:80 -v /${pwd}://usr/share/nginx/html --name nginxwebsite nginx
make sure to use extra
/before your 2 paths as/${pwd}and//usr/share/nginx/hhtmlon windows.
- push the current container to docker hub:
docker push <username>/<repo_name>
Edit contianer files¶
- Edit files of
nginxcontainer on the fly
> docker container exec -it mynginx bash
> ls
> cd usr/share/nginx
- create a volume and grap the files into your local machine
docker container run -d -p 8080:80 -v /${pwd}://usr/share/nginx/html --name nginxwebsite nginx
make sure to use extra
/before your 2 paths as/${pwd}and//usr/share/nginx/hhtmlon windows.
Docker-machine
-
commands:
> docker-machine ls // list all machines > docker-machine start default // starts the default machine > docker-machine stop default //stops the default machine