查看Docker QuickStart的源代码
←
Docker QuickStart
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== Install == '''Ubuntu:''' <source lang=bash> $ sudo apt-get install docker.io docker-compose $ sudo usermod -aG docker $USER </source> '''Windows:''' * [https://www.shaileshjha.com/step-by-step-how-to-install-docker-in-windows/ Step by Step – How to Install Docker in Windows 10] * [https://docs.docker.com/docker-for-windows/install/ Install Docker Desktop on Windows] <br><br> == Quick Start == 在 https://cloud.docker.com 免费注册一个 Docker 账号 登录 docker hub: <source lang=bash> comcat@icamgo:~$ docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: noduino Password: Login Succeeded </source> 搜索镜像 docker search <source lang=bash> comcat@icamgo:~$ docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relati... 8741 [OK] mariadb MariaDB is a community-developed fork of M... 3063 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Crea... 647 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 63 centurylink/mysql Image containing mysql. Optimized to be li... 61 [OK] mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 54 deitch/mysql-backup REPLACED! Please use http://hub.docker.com... 41 [OK] bitnami/mysql Bitnami MySQL Docker Image 35 [OK] tutum/mysql Base docker image to run a MySQL database ... 34 schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 28 [OK] prom/mysqld-exporter 23 [OK] linuxserver/mysql A Mysql container, brought to you by Linux... 22 centos/mysql-56-centos7 MySQL 5.6 SQL database server 16 circleci/mysql MySQL is a widely used, open-source relati... 15 mysql/mysql-router MySQL Router provides transparent routing ... 13 arey/mysql-client Run a MySQL client from a docker container 12 [OK] imega/mysql-client Size: 36 MB, alpine:3.5, Mysql client: 10.... 8 [OK] openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6 yloeffler/mysql-backup This image runs mysqldump to backup data u... 6 [OK] fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron t... 4 [OK] genschsa/mysql-employees MySQL Employee Sample Database 2 [OK] ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK] jelastic/mysql An image of the MySQL database server main... 1 monasca/mysql-init A minimal decoupled init container for mysql 0 widdpim/mysql-client Dockerized MySQL Client (5.7) including Cu... 0 [OK] </source> 拉取官方 mysql 镜像 docker pull: <source lang=bash> </source> 推送你修改后的 mysql 镜像 docker push: <source lang=bash> $ docker push {username}/{镜像名}:{tag} </source> <br><br> == Pull image from docker hub == <source lang=bash> comcat@aisrv:/work/api.noduino/database$ docker pull mysql/mysql-server:5.5 5.5: Pulling from mysql/mysql-server 33a3a5e469a8: Pull complete afd5b2a51aab: Pull complete d3fcc85ceffc: Pull complete 9c58bb63c013: Pull complete Digest: sha256:db8aecdf439d2a5dcc509cca80deabb28a8b7370725d0c71f46957d0e257ffd6 Status: Downloaded newer image for mysql/mysql-server:5.5 comcat@aisrv:/work/api.noduino/database$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE emqwebhook 20170505 1a2e9eb03836 44 hours ago 33.65 MB <none> <none> 3fc8aea36f2d 46 hours ago 3.994 MB nginx latest 46102226f2fd 10 days ago 109.4 MB emqttd-docker-v2.1.2 latest a799525a9a73 2 weeks ago 34.3 MB mysql/mysql-server 5.5 89418f92e739 3 weeks ago 168.9 MB alpine 3.5 4a415e366388 9 weeks ago 3.987 MB </source> <br><br> == Run container == <source lang=bash> comcat@aisrv:/work/api.noduino/database$ docker run --name cos-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql/mysql-server:5.5 beb67efbda72bb356a2630624eff965e89d5477cf7f596176fa45cb036d7db75 comcat@aisrv:/work/api.noduino/database$ docker exec -it cos-mysql mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.55 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> comcat@aisrv:/work/api.noduino/database$ docker exec -it cos-mysql bash </source> <br><br> == RM container == <source lang=bash> comcat@aisrv:/work/api.noduino/database$ docker ps -a comcat@aisrv:/work/api.noduino/database$ docker rm beb67efbda72 beb67efbda72 comcat@aisrv:/work/api.noduino/database$ docker pull mysql/mysql-server:5.6 comcat@aisrv:/work/api.noduino/database$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 987ab5054b83 mysql/mysql-server:5.6 "/entrypoint.sh mysql" 18 minutes ago Up 18 minutes 3306/tcp mysql 52df2e0d29b2 emqttd-docker-v2.1.2 "/opt/emqttd/start.sh" 10 days ago Exited (137) 45 minutes ago emq20 </source> <br><br> == Export port == <source lang=bash> comcat@aisrv:/work/api.noduino/database$ docker run -tid --name emq20 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqttd-docker-v2.1.2 docker: Error response from daemon: Conflict. The name "/emq20" is already in use by container 52df2e0d29b28509b2daae48a345cb1a44b2b5ed3ff268507cf223059d9b You have to remove (or rename) that container to be able to reuse that name.. comcat@aisrv:/work/api.noduino/database$ docker start emq20 emq20 </source> <br><br> == Passing options to the server == <source lang=bash> $ docker run --name test -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/cos-db:/var/lib/mysql -d mysql/mysql-server:5.6 --explicit_defaults_for_timestamp=true </source> <br><br> == Mount host dir == * place the dumped data file tempdb-xxx.sql in host dir cos-db/ * not support the sym link <source lang=bash> comcat@aisrv:/work/api.noduino/database$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/cos-db:/var/lib/mysql -d mysql/mysql-server:5.6 987ab5054b83a14a2249650715353b4b9dddb0e78fcbc514ae37be975ca4c145 comcat@aisrv:/work/api.noduino/database$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 987ab5054b83 mysql/mysql-server:5.6 "/entrypoint.sh mysql" 3 seconds ago Up 2 seconds 3306/tcp mysql comcat@aisrv:/work/api.noduino/database$ ls cos-db auto.cnf ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock performance_schema tempdb20170407.sql comcat@aisrv:/work/api.noduino/database$ docker exec -it mysql bash bash-4.2# ls /var/lib/mysql/ auto.cnf ib_logfile0 ib_logfile1 ibdata1 mysql mysql.sock performance_schema tempdb20170407.sql bash-4.2# head /var/lib/mysql/tempdb20170407.sql head: cannot open '/var/lib/mysql/tempdb20170407.sql' for reading: No such file or directory bash-4.2# exit exit comcat@aisrv:/work/api.noduino/database$ rm cos-db/tempdb20170407.sql comcat@aisrv:/work/api.noduino/database$ cp ../backup/tempdb20170407.sql cos-db/ comcat@aisrv:/work/api.noduino/database$ docker exec -it mysql bash bash-4.2# head /var/lib/mysql/tempdb20170407.sql -- MySQL dump 10.13 Distrib 5.5.49, for debian-linux-gnu (x86_64) -- -- Host: localhost Database: tempdb -- ------------------------------------------------------ -- Server version 5.5.49-0ubuntu0.14.04.1 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; </source> <br><br> == dump all databases == <source lang=bash> $ docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > all.sql </source> <br><br> == dump table column == <source lang=bash> $ cat cos-db/getdevid.sql select dvid from temp where productid='NNN1234' and uploadtime>'2017-03-01 00:00:00'; $ docker exec mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" tempdb </var/lib/mysql/getdevid.sql > /var/lib/mysql/alldevid' </source> <br><br> == Restore Database == <source lang=bash> $ cp cos-tempdb-170507.sql test/ $ docker run --name test -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/test:/var/lib/mysql -d mysql/mysql-server:5.6 --explicit_defaults_for_timestamp=true $ docker exec test sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" < /var/lib/mysql/cos-tempdb-170507.sql'; </source> <br><br> == Custom config file == <source lang=bash> $ docker exec -it cosdb cat /etc/my.cnf > my.cnf $ docker --name cosdb -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/my.cnf:/etc/my.cnf -v $(pwd)/test:/var/lib/mysql -d mysql/mysql-server:5.6 --explicit_defaults_for_timestamp=true </source> <br><br> == Using the data volume == * https://docs.docker.com/engine/tutorials/dockervolumes/#data-volumes <source lang=bash> </source> <br><br> == Notes == <source lang=bash> $ docker run --name mydb -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/mydb:/var/lib/mysql -d mysql/mysql-server:5.6 --explicit_defaults_for_timestamp=true $ docker exec mydb sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" < /var/lib/mysql/cos-tempdb-170507.sql'; $ docker run --name nginx-php -v $(pwd)/wxmp:/var/www/html --link mydb:mysql -d richarvey/nginx-php-fpm comcat@aisrv:/work/api.noduino/wxmp$ docker network ls NETWORK ID NAME DRIVER SCOPE 7fcde0337aa1 bridge bridge local 11451da05352 host host local b91f895fe12c none null local comcat@aisrv:/work/api.noduino/wxmp$ docker network inspect --format='{{json .Containers}}' 7fcde0337aa1 | python -m json.tool { "03535b5be172ce05c8ab5b43b8cdd80f9d04e3af8f47ba4911ea8fdc0161b87a": { "EndpointID": "d78fce5086d81cc0f9835018a50309a36b179bffb1a65848e2f2d74f5dc4e049", "IPv4Address": "172.17.0.2/16", "IPv6Address": "", "MacAddress": "02:42:ac:11:00:02", "Name": "mydb" }, "2d7d38840458c6666980453c16c3798cdab4655e97b470b1f145494705de344a": { "EndpointID": "de8090170c4e6a73c401a8175375cc595a7c50a9afcbb50b04e11cdf1c0af239", "IPv4Address": "172.17.0.3/16", "IPv6Address": "", "MacAddress": "02:42:ac:11:00:03", "Name": "nginx-php" } } # export port comcat@aisrv:/work/api.noduino/wxmp$ docker run -p 80:80 --name nginx-php -v $(pwd)/wxmp:/var/www/html --link mydb:mysql -d richarvey/nginx-php-fpm 054878b224c2ec32b67d80bbba50d605566bf1b6f19a9921c898dbd73d504647 </source> <br><br> == nignx-php == Install PHP Modules To install and configure extra PHP modules in this image, first of all drop into the container: docker exec -t -i nginx /bin/bash Then configure and install your module: /usr/local/bin/docker-php-ext-configure sockets /usr/local/bin/docker-php-ext-install sockets Now restart php-fpm: supervisorctl restart php-fpm We may include a env var to do this in the future. <br><br> == Export Container == <pre> $ sudo docker export <CONTAINER ID> > /home/export.tar </pre> == Restore Container == <pre> $ cat /home/export.tar | sudo docker import - api-elec:latest </pre> <br> == Commit == <source lang=bash> comcat@aisrv:/work/docker$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1bfd19e8626 srv-xda-api:0.9 "docker-php-entrypoin" 7 minutes ago Up 7 minutes 443/tcp, 9000/tcp, 0.0.0.0:8000->80/tcp xda-srv comcat@aisrv:/work/docker$ docker stop e1 e1 comcat@aisrv:/work/docker$ docker commit e1b srv-xda-api:0.9.2 sha256:f39c64c92367be2569d98ce889d4863dbb85f30bc425ecd0fdeea21bb43eb486 comcat@aisrv:/work/docker$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv-xda-api 0.9.2 f39c64c92367 5 seconds ago 345.2 MB srv-xda-api 0.9 a160e6e42d1c 9 minutes ago 345.2 MB comcat@aisrv:/work/docker$ docker run -d -e DB_HOST="192.168.1.20" -p 8000:80 srv-xda-api:0.9.2 4e6bfec25da6d33d3b9a3aa03b62f07ce2f8e61528e7292b140da99d80cef767 comcat@aisrv:/work/docker$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4e6bfec25da6 srv-xda-api:0.9.2 "docker-php-entrypoin" 3 seconds ago Up 2 seconds 443/tcp, 9000/tcp, 0.0.0.0:8000->80/tcp fervent_stonebraker </source> == Reference == * https://github.com/docker/labs/blob/master/developer-tools/nodejs/porting/4_single_host_networking.md * https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql === PowerShell === * [https://www.pstips.net/powershell-introduction-and-install.html Powershell 介绍和安装] * [https://www.pstips.net/powershell-environment-variables.html Powershell环境变量] * [https://www.pstips.net/powershell-automatic-variables.html Powershell自动化变量] * [https://www.pstips.net/powershell-define-variable.html Powershell 定义变量] * [https://www.pstips.net/powershell-invoking-files-and-scripts.html Powershell 执行文件和脚本] * [https://www.pstips.net/powershell-create-and-start-scripts.html Powershell 编写和运行脚本] * [https://www.pstips.net/powershell-as-a-calculator.html Powershell 进行数学运算] * [https://www.pstips.net/powershell-executing-external-commands.html Powershell 执行外部命令] * [https://www.pstips.net/powershell-cmdlets.html Powershell 命令集 cmdlets] * [https://www.pstips.net/powershell-alias.html Powershell 别名] * Powershell 循环 [https://www.pstips.net/powershell-for-loop.html For][https://www.pstips.net/powershell-foreach-loop.html Foreach][https://www.pstips.net/powershell-do-while-loop.html Do While][https://www.pstips.net/powershell-switch-loop.html Switch] * [https://www.pstips.net/powershell-formulating-conditions.html Powershell 条件操作] * [https://www.pstips.net/powershell-finding-built-in-cmdlets.html 在PowerShell中使用Vim] * [https://www.pstips.net/powershell-sql%E4%BA%8B%E5%8A%A1.html Powershell sql事务] <br><br> === IIS === Create a Dockerfile with your website <pre> FROM mcr.microsoft.com/windows/servercore/iis RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\* WORKDIR /inetpub/wwwroot COPY content/ . </pre> You can then build and run the Docker image: $ docker build -t iis-site . $ docker run -d -p 8000:80 --name my-running-site iis-site There is no need to specify an ENTRYPOINT in your Dockerfile since the microsoft/iis base image already includes an entrypoint application that monitors the status of the IIS World Wide Web Publishing Service (W3SVC). Verify in the browser With the current release, you can't use http://localhost to browse your site from the container host. This is because of a known behavior in WinNAT, and will be resolved in future. Until that is addressed, you need to use the IP address of the container. Once the container starts, you'll need to finds its IP address so that you can connect to your running container from a browser. You use the docker inspect command to do that: <source lang=bash> docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" my-running-site </source> You will see an output similar to this: 172.28.103.186 You can connect the running container using the IP address and configured port, http://172.28.103.186:8000 in the example shown. In addition to static content, IIS can run other workloads including but not limited to ASP.NET, ASP.NET Core, NodeJS, PHP, and Apache Tomcat. For a comprehensive tutorial on running an ASP.NET app in a container, check out the tutorial on the docs site. [https://docs.microsoft.com/zh-cn/aspnet/mvc/overview/deployment/docker-aspnetmvc 将 ASP.NET MVC 应用程序迁移到 Windows 容器] <br><br> === ASP.NET === * https://hub.docker.com/_/microsoft-dotnet-framework-aspnet <pre> Featured Tags 4.8 docker pull mcr.microsoft.com/dotnet/framework/aspnet:4.8 3.5 docker pull mcr.microsoft.com/dotnet/framework/aspnet:3.5 About This Image ASP.NET is a high productivity framework for building Web Applications using Web Forms, MVC, Web API and SignalR. This image contains: Windows Server Core as the base OS IIS 10 as Web Server .NET Framework (multiple versions available) .NET Extensibility for IIS Watch dotnet/announcements for Docker-related .NET announcements. How to use these Images The .NET Framework Docker samples show various ways to use .NET Framework and Docker together. Container sample: Run an ASP.NET application You can quickly run a container with a pre-built sample ASP.NET Docker image, based on the [ASP.NET Docker sample]. Type the following Docker command: docker run --name aspnet_sample --rm -it -p 8000:80 mcr.microsoft.com/dotnet/framework/samples:aspnetapp After the application starts, navigate to http://localhost:8000 in your web browser. You need to navigate to the application via IP address instead of localhost for earlier Windows versions, which is demonstrated in View the ASP.NET app in a running container on Windows. Related Repos .NET Framework: dotnet/framework/sdk: .NET Framework SDK dotnet/framework/runtime: .NET Framework Runtime dotnet/framework/wcf: Windows Communication Framework (WCF) dotnet/framework/samples: .NET Framework, ASP.NET and WCF Samples .NET Core: dotnet/core: .NET Core dotnet/core-nightly: .NET Core (Preview) dotnet/core/samples: .NET Core Samples </pre> <br><br> <br><br> <br><br>
返回到
Docker QuickStart
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面