English 中文(简体)
是否在 do弄者开学时失踪?
原标题:Is there something missing in docker getting-started tutorial?

I m 正在通过启程(。 https://www.docker.com/101-tutorial。 - 多克台式台,他们在这里有这种cker器:

version: "3.7"

services:
  app:
    image: node:12-alpine
    command: sh -c "yarn install && yarn run dev"
    ports:
      - 3000:3000
    working_dir: /app
    volumes:
      - ./:/app
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: todos

  mysql:
    image: mysql:5.7
    volumes:
      - todo-mysql-data:/var/lib/mysql
    environment: 
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos

volumes:
  todo-mysql-data:

The problem is that MySQL is not creating the "todos" database. And then my application can t connect to it giving me this error:

app_1    | Error: ER_HOST_NOT_PRIVILEGED: Host  172.26.0.2  is not allowed to connect to this MySQL server
app_1    |     at Handshake.Sequence._packetToError (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
app_1    |     at Handshake.ErrorPacket (/app/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
app_1    |     at Protocol._parsePacket (/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
app_1    |     at Parser._parsePacket (/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
app_1    |     at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
app_1    |     at Protocol.write (/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
app_1    |     at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:91:28)
app_1    |     at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:525:10)
app_1    |     at Socket.emit (events.js:310:20)
app_1    |     at addChunk (_stream_readable.js:286:12)
app_1    |     --------------------
app_1    |     at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
app_1    |     at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
app_1    |     at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
app_1    |     at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
app_1    |     at Pool.query (/app/node_modules/mysql/lib/Pool.js:202:8)
app_1    |     at /app/src/persistence/mysql.js:35:14
app_1    |     at new Promise (<anonymous>)
app_1    |     at Object.init (/app/src/persistence/mysql.js:34:12)
app_1    |     at processTicksAndRejections (internal/process/task_queues.js:97:5) {
app_1    |   code:  ER_HOST_NOT_PRIVILEGED ,
app_1    |   errno: 1130,
app_1    |   sqlMessage: "Host  172.26.0.2  is not allowed to connect to this MySQL server",
app_1    |   sqlState: undefined,
app_1    |   fatal: true
app_1    | }

如果我独自管理这一指挥,以掌握MySQL,则建立了“todos”数据库:

docker run -d --network todo-app --network-alias mysql -v todo-mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=todos mysql:5.7

是否有任何指挥系统得到更新,有的指挥系统在窗户上与cker子公司适当工作?

最佳回答

TL;DR;

指挥

docker-compose down --volumes

为了消除在教学初期阶段产生的任何问题量,随后在以下步骤中恢复指导:


我相信,你所遵循的是

如果你以零敲碎打的方式跟踪并尝试了第1步或第2步中的,那么,你可能在没有<编码>todos数据库的情况下创建了volume

∗∗∗∗∗ 只得赢了一定数量,因为确实为此投入了数量,数量是杜克永久储存层。

违约后,集装箱内生成的所有档案都储存在一个可修复的集装箱内。 这意味着:

  • The data doesn’t persist when that container no longer exists, and it can be difficult to get the data out of the container if another process needs it.
  • A container’s writable layer is tightly coupled to the host machine where the container is running. You can’t easily move the data somewhere else.
  • Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem.

多克有两种选择,即集装箱存放在东道机器的档案,这样,甚至在集装箱停泊后,档案就会继续存在:数量和装货。 如果你把Docker投向北纬度线,你也可以使用一种波纹。 如果你在视窗上操作多克,你也可以使用一个指定管道。

Source:https://docs.docker.com/storage/

为了删除该卷,你很可能在没有你的数据库的情况下创建,你可以增加一个旗帜,在<条码>上添加“dcker-composedown: www.un.org/Depts/DGACM/index_spanish.htm

-v, --volumes          Remove named volumes declared in the "volumes" section
                       of the Compose file and anonymous volumes attached to
                       containers.

Source:https://docs.docker.com/compose/参比/down/


因此,你的定点应当简单明了:

  1. docker-compose down --volumes
  2. docker-compose up -d, so back in your tutorial at the step Running our Application Stack
  3. docker-compose logs -f as prompted in the rest of the tutorial
问题回答

目前,在你发射码头时,你将重置数据库,在你本人的舱内制造。

In fact, your issue come from mysql user permission.

www.un.org/Depts/DGACM/index_spanish.htm 在您的档案中,添加以下一线,该数据库最初是。

  CREATE USER  newuser @ %  IDENTIFIED BY  user_password ;

该行将建立一个用户:newuser,并允许用户从host<>>>>>>>>>>> > 查阅密码 用户_password<>。

www.un.org/Depts/DGACM/index_spanish.htm 1. 本行:

GRANT ALL PRIVILEGES ON *.* TO  newuser @ % ;

它准许每个数据库和每个桌上的所有许可,请newuser>>>> ><>>>> > 查询。

最后,改变你的神秘环境变数MYSQL_USER和MYSQL_PASSWORD,与你刚刚创造的新环境。

version: "3.7"

services:
  app:
    image: node:12-alpine
    command: sh -c "yarn install && yarn run dev"
    ports:
      - 3000:3000
    working_dir: /app
    volumes:
      - ./:/app
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: newuser
      MYSQL_PASSWORD: user_password
      MYSQL_DB: todos

  mysql:
    image: mysql:5.7
    volumes:
      - todo-mysql-data:/var/lib/mysql
    environment: 
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos

volumes:
  todo-mysql-data:

I used Docker Desktop->Volumes, selecting todo-mysql-data and deleted it. Then, the issue is resolved. enter image description here





相关问题
Unable to connect to docker container inside windows server

As title. I am developing a system with many docker images with ASP.Net MVC core projects. I am publishing these docker images into a docker engine installed on Windows Server OS, and I found that I ...

Only can see postgreSQL as an admin

After installed Wsl and Docker, can t access PSQL and other things. I was studying Docker, and installed the latest version. So far so good, I received an error about the WSL version, saw some ...

make docker-compose block until healthy without `depends_on`

I am working with a team that uses docker-compose to start a set of helper services, but does not use docker when the code is being developed. Here, docker-compose is just a convenient way to run the ...

change grafana port using docker host network

I am trying to spin up a grafana container in docker, however my setup in docker does not allow ipv4 forwarding and thus I cannot use the default bridge network in docker. All I can use is the host ...

Pip instalation for Python 3.11 in docker

I have Dockerfile to build image for Django project that uses Python 3.11 and runs in poetry environment (see content below). Problem is when I try to donwload get-pip.py file and run it using Python, ...

在 Dockerfile 中运行 composer install

我正在尝试将我的Laravel应用程序进行Docker化。 该应用程序已经构建并在Git中,但我将vendor文件夹添加到了.gitignore中。 我添加了一个Dockerfile,看起来像这样: FROM php:7.1-fpm-alpine RUN apk update ...