在交互模式下使用 docker run 时如何为容器分配名称?
例如,运行此命令
docker run -d -it docker_image_already_created sh
Run Code Online (Sandbox Code Playgroud)
检查时docker ps名称是自动生成的。容器名称如何传递?
我在一个 php 项目中有一个 Dockerfile,我需要在执行过程中传递一个用户和一个密码来下载一个库。
用户和密码必须隐藏在生产环境或本地 .env 文件中。目前我只是尝试本地选项,用户和密码为空。
我使用了"${USER}"and ${USER},但不仅登录失败,而且当我打印变量时,它们变空了。我也试过把变量硬编码,它工作正常,所以问题是变量不是从 .env 文件中检索的。
docker-compose 启动如下
version: '3'
services:
server:
build:
context: .
dockerfile: docker/Server/Dockerfile
container_name: "server"
ports:
- 80:80
- 8888:8888
networks:
- network
env_file:
- .env
command: sh /start-workers.sh
Run Code Online (Sandbox Code Playgroud)
和 Dockerfile:
FROM php:7.3-cli-alpine3.10
RUN apk add --update
#
# Dependencies
#
RUN apk add --no-cache --no-progress \
libzip-dev zip php7-openssl pkgconfig \
php-pear php7-dev openssl-dev bash \
build-base composer
#
# Enable PHP extensions
#
RUN docker-php-ext-install bcmath …Run Code Online (Sandbox Code Playgroud) 我需要在 Symfony 4 中对订阅者进行功能测试,但我在寻找方法时遇到了问题。订阅者具有以下结构
/**
* Class ItemSubscriber
*/
class ItemSubscriber implements EventSubscriberInterface
{
/**
* @var CommandBus
*/
protected $commandBus;
/**
* Subscriber constructor.
*
* @param CommandBus $commandBus
*/
public function __construct(CommandBus $commandBus)
{
$this->commandBus = $commandBus;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
CommandFailedEvent::NAME => 'onCommandFailedEvent',
];
}
/**
* @param CommandFailedEvent $event
*
* @throws Exception
*/
public function onCommandFailedEvent(CommandFailedEvent $event)
{
$item = $event->getItem();
$this->processFailed($item);
}
/**
* Sends message …Run Code Online (Sandbox Code Playgroud) 我正在使用int [n] [n]板:
0 2 3
4 1 5
7 8 6
Run Code Online (Sandbox Code Playgroud)
我想制作一个称为twin的副本,然后返回修改后的副本。
例如:
int [][] twin = board.clone();
twin[0][0] = board[0][1];
twin[0][1] = board[0][0];
return twin;
Run Code Online (Sandbox Code Playgroud)
我所期望的是:
//board
0 2 3
4 1 5
7 8 6
//twin
2 0 3
4 1 5
7 8 6
Run Code Online (Sandbox Code Playgroud)
但是结果是:
//board
2 2 3
4 1 5
7 8 6
//twin
2 2 3
4 1 5
7 8 6
Run Code Online (Sandbox Code Playgroud)
董事会和双胞胎一直都是一样的,克隆无法正常工作。是否因为int [] []不是对象?
有没有办法克隆int [] []并修改我期望的方式?我应该遍历所有并将值复制到twin吗?
我正在使用promises,我需要知道异步方法处理的所有项目的结果。所以我认为Promise.all()可以解决我的问题,例如:
const values = await Promise.all(items.map((item) => {
asyncMethodThatLogsAndReturnsBoolean(item);
}));
console.log(values);
Run Code Online (Sandbox Code Playgroud)
我在这里发现的是,在值日志之后会打印一些异步方法的日志。并且values被打印为的数组undefined。
是否有任何原因为什么该实现不等到所有的承诺都解决后才能为值对象打印正确的数据?
* asyncMethodThatLogsAndReturnsBoolean(item)调用了其他异步方法,但是所有调用都有await。
docker ×2
php ×2
async-await ×1
clone ×1
containers ×1
dockerfile ×1
events ×1
int ×1
java ×1
node.js ×1
promise ×1
symfony4 ×1
testing ×1