我需要在需要两个终端的docker容器上启动两个不同的进程,实现此目的的最佳方法是什么?
Answers:
扩展@eltonStoneman的好答案(对于所有像我这样的新docker员工):
打开一个码头
使图像作为容器在后台运行: docker run -d -it <image_id>
docker ps
根据@eltonStoneman的建议: docker exec -it <container_id> bash
打开另一个docker终端,然后执行步骤3,为该容器创建另一个交互式终端。(重复冲洗)
docker ps
一点。顺便说一句,至少在Linux上,可以使用普通终端(不需要是“ docker终端”)
ps aux
在任何终端中运行,我都会看到我启动的所有终端。
docker run -it container_name bash
使用bash promt启动一个新容器。
docker exec -it container_name bash
加入已经运行的容器的bash提示符。
如果您能够运行Kitematic,则可以单击exec按钮以打开所选容器中的终端。
使用Docker Compose:假设您有一个启用X-Windows的Compose yml。
您可以按照以下步骤启动图形IDE(例如qtCreator),nautilus和终端窗口的终端。
假设:
Dockerfile: Dockerfile-dev-ubuntu_xenial-创建Docker映像
FROM ubuntu:xenial
ARG DEBIAN_FRONTEND=noninteractive
LABEL maintainer "Your NAME <your.address@yourmailhost.com>"
RUN apt-get update ; apt-get install -y apt-utils desktop-file-utils dialog nautilus build-essential debhelper fakeroot ccache lsb-release
RUN apt-get install -y autotools-dev autoconf pkg-config libtool curl gedit git wget unzip lintian
RUN apt-get install -y qtcreator valgrind
RUN apt-get install -y sudo \
&& groupadd -r user -g 1000 \
&& useradd -u 1000 -r -g user -m -d /user -s /sbin/nologin -c "Build pkg user" user \
&& chmod 755 /user \
&& echo "user ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/user \
&& chmod 0440 /etc/sudoers.d/user
WORKDIR /user
USER user
VOLUME ["/buildpkg", "/user/projects", "/user/resources"]
CMD /bin/bash
Compose.yml: compose-dev-linux.yml
version: '3'
services:
# Commands:
# Build: docker-compose -f compose-dev-linux.yml build dev_ubuntu_xenial
# Up : docker-compose -f compose-dev-linux.yml up -d dev_ubuntu_xenial
# Run : docker-compose -f compose-dev-linux.yml run dev_ubuntu_xenial
# Down : docker-compose -f compose-dev-linux.yml down
# Host folders:
# %USERPROFILE%/Projects
# %USERPROFILE%/Projects/Docker-builds
# %USERPROFILE%/Projects/Docker-resources
# Docker configuration file locations:
# %USERPROFILE%/Dockerfiles/Dockerfile-dev-ubuntu_xenial
# %USERPROFILE%/compose-dev-linux.yml
dev_ubuntu_xenial:
security_opt:
- seccomp:unconfined
cap_add:
- SYS_ADMIN
environment:
- DISPLAY=192.168.1.101:0
network_mode: host
image: "application-dev-platform/application:ubuntu_xenial"
container_name: application-dev-ubuntu_xenial
command: bash -c "/bin/bash"
tty: true
build:
context: ./Dockerfiles
dockerfile: Dockerfile-dev-ubuntu_xenial
volumes:
- ./Projects:/user/projects
- ./Projects/Docker-builds:/buildpkg
- ./Projects/Docker-resources:/user/resources
运行: -初始Powershell终端
docker-compose -f compose-dev-linux.yml build dev_ubuntu_xenial
docker-compose -f compose-dev-linux.yml up -d dev_ubuntu_xenial
docker ps
docker exec -it <CONTAINER ID> bash
user@linuxkit-<generatedid>:~$ qtcreator
运行: -新的Powershell终端
docker exec -it <CONTAINER ID> bash
nautilus
运行: -新的Powershell终端
docker exec -it <CONTAINER ID> bash
user@linuxkit-<generatedid>:~$