articolo introduttivo:

Stati di un container

  • created: A container that has been created (e.g. with docker create) but not started
  • restarting: A container that is in the process of being restarted
  • running: A currently running container
  • paused: A container whose processes have been paused
  • exited: A container that ran and completed ("stopped" in other contexts, although a created container is technically also "stopped")
  • dead: A container that the daemon tried and failed to stop (usually due to a busy device or resource used by the container)

immagine nginx sull hub per fare dei test

MEMO: ricorda di pulire i container che si generano!!!

docker run --name my-nginx -d -p 8081:80 nginx

poi vai su http://localhost:8081/ e vedi  il server web UP

root@Itaca-Laptop:~# docker container ls --all
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
adc675ca5295        nginx               "nginx -g 'daemon of…"   9 seconds ago       Up 7 seconds>80/tcp   my-nginx

root@Itaca-Laptop:~# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mynginx             latest              a588c72fa352        4 hours ago         89.8MB

per fare una macchina custom ti serve un file Dockerfile (dal tutorial SpringBoot

FROM openjdk:8-jre-alpine
COPY SBHelloWorld-0.0.1-SNAPSHOT.jar .
CMD java -jar /SBHelloWorld-0.0.1-SNAPSHOT.jar

metti il jar nella stessa cartella del Dockerfile ed esegui

sudo docker build -t hellow -f Dockerfile .
sudo docker image ls
docker run -d -p 4000:8080 hellow
sudo docker container ls
dal broswer http://localhost:4000/

Comandi base:

## List Docker CLI commands
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Execute Docker image
docker run hello-world

## List Docker images
docker image ls

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq

sudo service docker start/stop/restart

# processi running
sudo docker ps

sudo docker build -t mynginx -f Dockerfile . (ci vuole il punto finale ??!!)

# lancio di un container con shel aperta
docker run -it  openjdk  sh

sudo docker run -d -p 4000:80 mynginx 

sudo docker run -d -p openjdk:8-jre-alpine /bin/bash

sudo docker stop openjdk:8-jre-alpine

docker rmi <image name>

export in file tar:

sudo docker image ls
sudo docker save -o /miopath/mio.tar nome _immagine
sudo docker load -i <path to copied image file>