-
Notifications
You must be signed in to change notification settings - Fork 44
NOTE20210721
Somkiat Puisungnoen edited this page Jul 22, 2021
·
7 revisions
docker container run hello-world
docker container run hello-world:latest
docker image ls
docker container ps
docker container ps -a
docker container prune
- Docker Image
- hello-world:latest
- name:tag
- Docker Registry
- Dockerfile
- Docker Container
$docker container run -d --name db \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=demo \
-e MYSQL_USER=somkiat \
-e MYSQL_PASSWORD=pass \
mysql:8.0.26
$docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b95c3d76c1b mysql:8.0.26 "docker-entrypoint.s…" 49 seconds ago Up 48 seconds 3306/tcp, 33060/tcp db
$docker container logs db --follow
Initial data of container
file data.sql
use demo;
CREATE TABLE user (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL
);
INSERT INTO user(name) VALUES ("A");
INSERT INTO user(name) VALUES ("B");
INSERT INTO user(name) VALUES ("C");
$docker container run -d --name db \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=demo \
-e MYSQL_USER=somkiat \
-e MYSQL_PASSWORD=pass \
-v $(pwd)/data.sql:/docker-entrypoint-initdb.d/1.sql \
mysql:8.0.26
$docker container logs db --follow
$docker container exec -it db bash
#mysql -usomkiat -ppass
#use demo
#show tables;
#select * from user;
// Use volume from container to Host
$docker container run -d --name db \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=demo \
-e MYSQL_USER=somkiat \
-e MYSQL_PASSWORD=pass \
-v $(pwd)/data.sql:/docker-entrypoint-initdb.d/1.sql \
-v $(pwd)/data:/var/lib/mysql \
mysql:8.0.26
// Use docker volume=example
$docker container run -d --name db \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=demo \
-e MYSQL_USER=somkiat \
-e MYSQL_PASSWORD=pass \
-v $(pwd)/data.sql:/docker-entrypoint-initdb.d/1.sql \
-v example:/var/lib/mysql \
mysql:8.0.26
Create Docker Image
- Create from container
- Create from Dockerfile (Docker way)
Push image from Host to Docker Registry (Docker Hub)
$docker container run -d --name web nginx:1.21.1
$docker container exec -it web bash
$docker container commit web myweb:1.0.0
Format of image name
- myweb // Official image => Docker Hub
- username/myweb // User image => Docker Hub
- somkiat/myweb
- 192.168.10.11:port/myweb => 192.168.10.11
$docker login
$docker image tag myweb:1.0.0 somkiat/myweb:1.0.0
$docker image push somkiat/myweb:1.0.0
``
### Create image from Dockerfile
FROM nginx:1.21.1 ENV key=value ENV key2=value2 RUN apt update && apt install wget -y
Create image
$docker image build -t myweb:0.0.1 -f Dockerfile .