If there is no database initialized when the container starts, then a default database will be created. While this is the expected behavior, this means that it will not accept incoming connections until such initialization completes. This may cause issues when using automation tools, such as docker-compose, which start several containers simultaneously.
If the application you’re trying to connect to MySQL does not handle MySQL downtime or waiting for MySQL to start gracefully, then a putting a connect-retry loop before the service starts might be necessary. For an example of such an implementation in the official images, see WordPress or Bonita.
-- 不应该在这里直接删除'root'@'%',否则会影响原本root应有的权限。可以通过该命令查看该命令的影响,SHOW GRANTS FOR 'root'@'%'; -- 如果不删用户root,会出现该权限 GRANT ALL PRIVILEGES ON *.* to 'root'@'%' WITH GRANT OPTION -- 如果删了用户root,会出现该权限 GRANT USAGE ON *.* to 'root'@'%' -- drop user 'root'@'%';
-- 密码在启动mysql容器或者在docker-compose.yml文件中时就应该指定,如 -- docker run -e MYSQL_ROOT_PASSWORD=test mysql:5.7.22 -- 或 -- environment: -- - MYSQL_ROOT_PASSWORD=test -- CREATE USER 'root'@'%' IDENTIFIED BY 'test';
GRANTALL PRIVILEGES ON YOU_DATABASE.*TO'root'@'%';
当然建库建表前应该用if判断,不判断也行,因为本来就是新实例。
1 2 3 4 5 6 7 8
DROP DATABASE IF EXISTS YOUR_DATABASE; CREATE DATABASE YOUR_DATABASE;
The CMD instruction should be used to run the software contained by your image, along with any arguments. Indeed, this form of the instruction is recommended for any service-based image. like:
CMD [“executable”, “param1”, “param2”…]
CMD [“apache2”,”-DFOREGROUND”]
CMD命令还用在交互式的shell中,如bash,python,perl。例如以下几个用法。 使用这种方式的好处是你能够执行如 docker run -it python 就能直接进入到一个有用的shell中。
CMD [“perl”, “-de0”], CMD [“python”], or CMD [“php”, “-a”]
We use tabs for indentation(使用tab来缩进) and gofmt emits them by default. Use spaces only if you must.(仅在必要时使用空格)
Line length
Go has no line length limit. Don’t worry about overflowing a punched card. If a line feels too long, wrap it and indent with an extra tab.
Parentheses
Go needs fewer parentheses(更少的括号) than C and Java: control structures (if, for, switch) do not have parentheses in their syntax. Also, the operator precedence hierarchy is shorter and clearer