写点什么

Docker

用户头像
云淡风轻
关注
发布于: 2020 年 12 月 21 日

Docker Desktop

Docker Desktop is a native application that delivers all of the Docker tools to your Mac or Windows Computer. 

  1. Open Docker Desktop. (Download here if you don't have it).

  2. Type the following command in your terminal: docker run -dp 80:80 docker/getting-started

  3. Open your browser to http://localhost

  4. Have fun!

The Docker Dashboard


What is a container

a container is simply another process on your machine that has been isolated from all other processes on the host machine.

What is a container image?

When running a container, it uses an isolated filesystem. This custom filesystem is provided by a container image. Since the image contains the container's filesystem, it must contain everything needed to run an application - all dependencies, configuration, scripts, binaries, etc. The image also contains other configuration for the container, such as environment variables, a default command to run, and other metadata.

Create a Repo

To push an image, we first need to create a repo on Docker Hub.

  1. Go to Docker Hub and log in if you need to.

  2. Click the Create Repository button.

  3. For the repo name, use getting-started. Make sure the Visibility is Public.

  4. Click the Create button!

Pushing our Image

$ docker push docker/getting-started


Persisting our DB

The Container's Filesystem
Container Volumes

docker volume create todo-db


Play with Docker

Play with Docker is an interactive playground that allows you to run Docker commands on a linux terminal, no downloads required.

  1. Log into https://labs.play-with-docker.com/ to access your PWD terminal

  2. Type the following command in your PWD terminal: docker run -dp 80:80 docker/getting-started:pwd

  3. Wait for it to start the container and click the port 80 badge

  4. Have fun!


Docker install Mysql

docker search mysql

docker pull mysql


docker images

docker rmi images

docker run images

docker run -p 3307:3306 --name mysql03 -e MYSQLROOTPASSWORD=123456 -d mysql


docker stop container

docker start container

docker rm container


Docker install Tomcat

docker pull tomcat

docker run -d -p 8080:8080 tomcat

docker logs containerID


Docker Commands

Starting an App container

docker run -d -p 80:80 docker/getting-started

Building a new container image

docker build -t getting-started .

Get the ID of the container

docker ps

stop the container

docker stop <the-container-id>

remove the container

docker rm <the-container-id>

Push image

docker push docker/getting-started

give the getting-started image a new name

docker tag getting-started YOUR-USER-NAME/getting-started

Where is Docker actually storing my data when I use a named volume?

docker volume inspect todo-db


Appendix

Docker Home Page

https://www.docker.com/get-started

Docker Hub

https://hub.docker.com/

Play With Docker

https://labs.play-with-docker.com/


用户头像

云淡风轻

关注

云淡风轻 2018.08.18 加入

JAVA软件工程师

评论

发布
暂无评论
Docker