This page - https://bit.ly/2MezS0z
docker [resource/object] [command] [options] [args]
1. $ docker --version
2. $ docker version
3. $ docker info
4. $ docker image ls (list images)
5. $ docker container ls (or ps) (list containers)
6. $ docker volume ls
7. $ docker network ls
1. $ docker image pull alpine
2. $ docker image ls
3. $ docker image history alpine
4. $ docker container create -it alpine
5. $ docker container ps -a
6. $ docker container create -it --name alpine1 alpine
7. $ docker container start alpine1
8. $ docker container attach alpine1
/# cat /etc/os-release ; exit
9 $ docker container start alpine1;
## Running commands in a live container
10. $ docker container exec alpine1 cat /etc/issue
11. $ docker container rm --force alpine1
1. $ docker container run -it --name alpine2 --rm alpine
/# ps aux; exit
2. $ docker container run -d -it --name alpine2 alpine (detached)
3. $ docker container exec alpine2 cat /etc/os-release
4. $ docker container attach alpine2
/$ exit
TERMINAL 1
1. docker container run -it --name alpine3 --rm alpine
/# ps aux
TERMINAL 2
2. docker container logs -f alpine3
3. docker container logs -f alpine3
1. $ docker container run --rm --name wearebigchill -p 8080:80 rselva/wearebigchill:beta
Play @ http://localhost:8080
1. $ git clone https://github.com/spkane/wearebigchill.git --config core.autocrlf=input
2. $ cd wearebigchill
3. $ docker image build -t wearebigchill:beta .
4. $ docker image ls
5. $ docker container run --rm --name wearebigchill -p 8080:80 wearebigchill:beta
6. $ docker container rm --force wearebigchill
7. $ docker container run --rm --name wearebigchill -p 8080:80 -e "THEME=2" wearebigchill:beta
a. Create volume; run a container with that volume; delete container; run another container with the same volme
1. $ docker volume create user-db-volume
2. $ docker container run -it --rm -v user-db-volume:/home/db --name bb1 busybox sh
/# (Add some data)
3. $ docker container run -it --rm -v user-db-volume:/home/db alpine sh
#/ (look around)
1. $ cd temp; mkdir html ; echo "<h2>Welcom to my blog!</h1>" > html\index.html
2. $ docker container run -d -p 8080:80 -v E:/temp/html:/usr/share/nginx/html --name docker-nginx nginx
3. $ http://localhost:8080
4. $ docker container rm --force docker-nginx
import java.time.Instant;
public class Application {
public static void main(String[] args) {
System.out.println("Time now is "+ Instant.now());
}
}
FROM openjdk:8-jdk-alpine3.8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Application.java
CMD ["java", "Application"]
$ docker image build -t {tag} {build context}
$ docker image build -t time:beta .
$ docker image ls
$ docker container run time:beta
$ docker container run --name time-instance time:beta
Create HUBID @ https://hub.docker.com/
$ docker login
$ cat ~/.docker/config.json
$ docker image tag time:beta ${HUB_USER}/time:beta (rselva/time:beta)
$ docker image push rselva/time:beta
$ docker image rm rselva/time:beta
$ docker iamge ls
$ docker container run --rm rselva/time:beta
$ docker run -it --cap-add SYS_ADMIN --cap-add SYS_PTRACE --pid=host alpine nsenter -t 1 -m -u -n -i sh
$ cat etc/os-release
$ cat etc/issue
$ exit
1. $ docker images
2. $ docker image tag alpine:latest alpine:beta
3. $ docker container run --name myalpine -it alpine:beta sh
#/echo "Docker class" > class.txt
4. $ docker container commit myalpine alpine:beta2
5. $ docker image history alpine:beta2
6. $ docker image history alpine:beta
Store-App
+ product-service
+ web-app //Not covered today
+ mongodb
Step 1. Clone the repo or download from https://github.com/rselva/store-app.git
1. $ git clone https://github.com/rselva/store-app.git
2. $ cd store-app
1. $ cd product-service
2. $ mvn clean package --> .\target\product-service-0.1.0.jar
3. $ cat Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
4. $ docker image build --build-arg JAR_FILE=target/product-service-0.1.0.jar -t rselva/product-service:beta .
6. $ docker container run --rm -d -p 8080:8080 --name product-service rselva/product-service:beta
docker container logs -f -t product-service
http://localhost:8080
## Clean up
7. $ docker container rm --force product-service
- Declartive way to create an application stack.
- Compose the application from services
1. docker-compose build --no-cache
2. docker-compose up (-d for running in background)
3. docker-compose ps
4. docker-compose logs product-service
5. docker-compose exec product-service ps
version: '3.1'
services:
product-service:
build:
context: product-service\.
args:
JAR_FILE: ${JAR_FILE}
image: rselva/product-service:beta
environment:
DB: mongo
ports:
- 8080:8080
depends_on:
- mongo
networks:
- devnet
mongo:
image: mongo
restart: always
ports:
- 27017:27017
volumes:
- model-data-volume:/data/db
- model-config-volume:/data/configdb
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: hauX123
networks:
- devnet
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
depends_on:
- mongo
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: hauX123
networks:
- devnet
volumes:
model-data-volume:
model-config-volume:
networks:
devnet: