Container: isolated app that can be executed inside of it in every marhine without the need of any specific os version, making easy the microservices development.
Docker images: snapshot of a container that could have an ok and the Radarin app installed and ready to run in every machine.
There are many public images such as mongo, sql, java, etc.
We can install i.e an Ubuntu os and then install more software to create a custom image.
Docker shares resources with the OS of the pc that is executing its containers.
Docker works with os images that can be shared among several applications.
It isolates apps but not entire operating systems taking the resources as needed (betther that wasting memory on preassigned vm's).
docker pull ubuntu --> downloads the ubuntu image
docker pull ubuntu:16.04 --> downloads the image of that precise version
docker run hello-world --> creates a container with the "hello-world" image
Commands:
docker run --> runs commands to create a container
docker exec --> runs commands inside the container that is currently running
docker run ubuntu ls --> list the directories
docker ps -a --> shows the containers that are currently running
docker run ubuntu ls -la --> another listing. It creates a third container.
Docker run --name ubuntubash -i -t ubuntu bash
- --name: gives a name to the container
- -i: an execution of an interactive container
- -t: opens a new terminal tty
- ubuntu: image to run
- bash: command to execute
Exit from a docker container without removing it: Ctrl-p + ctrl-q
Inside a container, exit command terminates and removes the container
To exit the container without removing it: Ctrl-p + ctrl-q
Docker attach [Container_ID] --> you go into the container again
Start container: docker start ID
Stop container: docker stop ID
Pause: docker pause ID
Unpause: docker unpause ID
Docker images --> shows all the created images
Create custom images:
Docker run --name example -it ubuntu bash -->Creates new ubuntu container called example based on the ubuntu image
Apt update -->updates all the dependencies
Apt install vim -->install this text editor
Docker commit example ubuntu-example --> creates a configured image of ubuntu-example with all the installed stuff
Dockerfile
File that creates a customized docker image by creating a file specifying everything on it.
Dockerfile creation:
FROM ubuntu:18.04 --> image to intall
RUN apt -y update
RUN apt -y upgrade
RUN apt -y intall vim apache
There are many public images such as mongo, sql, java, etc.
We can install i.e an Ubuntu os and then install more software to create a custom image.
Docker shares resources with the OS of the pc that is executing its containers.
Docker works with os images that can be shared among several applications. It isolates apps but not entire operating systems taking the resources as needed (betther that wasting memory on preassigned vm's).
Download: https://docs.docker.com/get-docker/
Docker hub: you can search the desired image to download there: https://hub.docker.com/
docker pull ubuntu --> downloads the ubuntu image docker pull ubuntu:16.04 --> downloads the image of that precise version
docker run hello-world --> creates a container with the "hello-world" image
Commands:
Docker run --name ubuntubash -i -t ubuntu bash
Exit from a docker container without removing it: Ctrl-p + ctrl-q
Inside a container, exit command terminates and removes the container
Docker images --> shows all the created images
Create custom images:
Docker run --name example -it ubuntu bash -->Creates new ubuntu container called example based on the ubuntu image
Apt update -->updates all the dependencies
Apt install vim -->install this text editor
Docker commit example ubuntu-example --> creates a configured image of ubuntu-example with all the installed stuff
Dockerfile
File that creates a customized docker image by creating a file specifying everything on it.
Dockerfile creation:
FROM ubuntu:18.04 --> image to intall
RUN apt -y update RUN apt -y upgrade RUN apt -y intall vim apache
docker build -t "imageExample" . -t --> name . --> path