-
Notifications
You must be signed in to change notification settings - Fork 44
NOTE20181008
Somkiat Puisungnoen edited this page Jul 26, 2019
·
1 revision
$docker-machine ls
$docker-machine ip default
$docker image pull :
$docker images
$docker image ls
$docker image inspect nginx:1.15.5-alpin
$docker container run -d nginx:1.15.5-alpine
$docker container ls
$docker container ls -a
$docker container exec -it <container id> <shell>
$docker container exec -it <container id> sh
$docker container stop $(docker container ls -q)
$docker container prune
$docker rm -f $(docker ps -a -q)
$docker container run -d -p 8081:80 nginx:1.15.5-alpine
$docker container run -d -p 8082:80 nginx:1.15.5-alpine
$docker container run -d -p 8083:80 nginx:1.15.5-alpine
- Save image from container and push your image to registry (Docker Hub)
- Create image from Dockerfile (basic)
1. Create new container
$docker container run -d -p 8081:80 nginx:1.15.5-alpine
2. Execute to container and change data in file /usr/share/nginx/html/index.html
$docker container exec -it c0fb49c7b95c sh
#/exit
3. See diff in container
$docker container diff c0fb49c7b95c
4. Save container to new image
$docker container commit c0fb49c7b95c myweb:0.1
5. Try to create new container from new image
$docker container run -d -p 8082:80 myweb:0.1
Push new image to Registry (Docker Hub)
1. Login to Docker Hub
$docker login
2. Copy new image to correctly image name of Docker Hub
$docker image tag myweb:0.1 <your docker hub name>/myweb:0.1
$docker image tag myweb:0.1 somkiat/myweb:0.1
3. Push your image to Docker Hub
$docker image push somkiat/myweb:0.1
1. Create Dockerfile
$touch Dockerfile
FROM nginx:1.15.5-alpine
WORKDIR /usr/share/nginx/html
COPY . /usr/share/nginx/html
2. Build image from Dockerfile
$docker image build -t thai:0.1 .
3. Create container from new image
$docker container -d thai:0.1
Using -v (volume) => format <host path>:<container path>
$docker container run -d -p 8081:80 -v $(pwd):/usr/share/nginx/html nginx:1.15.5-alpine
For PWD (Play with docker)
1. Change own of folder and files to nginx
$chown -Rf nginx:nginx *
2. Create new container with volume
$docker container run -d -p 8081:80 -v $(pwd):/usr/share/nginx/html nginx:1.15.5-alpine
$ docker container run -d --rm hello-world
$docker run -dit --restart=always thai:0.1
Access to container and stop nginx process and see detail of container
$docker container exec -it 7a943f95c249 sh
#/kill 1
#exit
$ docker container ps