Docker MultiStage Build公开Web应用程序,并运行bash命令

时间:2018-04-17 15:51:31

标签: docker asp.net-core dockerfile

我有这个dockerfile。我正在尝试创建一个包含ubuntu和包含在其中的网站的图像。 ubuntu命令打开firefox并应导航到具有该网站的URL。 CMD部分按预期工作,但http:localhost:8080无效。这是dockerfile,我将引导您完成每个部分。

  

Dockerfile

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "SecondApp.dll"]

#ubuntu 16.04
FROM ubuntu:16.04
#set the working directory. All commands will be ran here
WORKDIR /root/
#Update packages, and install sudo
RUN apt-get update && apt-get install -y sudo
#not sure what all this does, but it gets the gui and firefox working
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/developer && \
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
    echo "developer:x:${uid}:" >> /etc/group && \
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
    chmod 0440 /etc/sudoers.d/developer && \
    chown ${uid}:${gid} -R /home/developer
#install firefox, wget and add chrome to sources
RUN apt-get update && apt-get install -y firefox
RUN apt-get install wget -y
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update
#install severel dependent packages for firefox and chrome
RUN apt-get install google-chrome-stable dbus-x11 packagekit-gtk3-module libcanberra-gtk-module libcanberra-gtk3-module -y
#xdotool is used for mimicking key presses 
RUN apt-get install xdotool -y
#not sure what this does either
RUN chown -R developer:developer /home/developer
RUN mkdir /var/run/dbus/
#? user
USER developer
ENV HOME /home/developer
#not sure what dbus-daemon does, but this does open up firefox, navigate to localhost:8080, and full screens the app. To keep the container running bin/bash is ran after, it remains in the background successfully.
CMD sudo dbus-daemon --system --fork && /usr/bin/firefox -url http://localhost:8080 & xdotool search --sync --onlyvisible --class "Firefox" windowactivate key F11  & /bin/bash
  

SecondApp

SecondApp只是Visual Studio 2017 for asp.net核心Web应用程序的默认创建应用程序。没有MVC,没有添加任何内容。调试时。导航到http:localhost:56545将显示主页。

所以从上面的dockerfile构建。使用此docker run命令

docker run -ti --rm -p 8080:80 -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix repo/repo

或者这个

docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix repo/repo

将运行容器,在url localhost:8080打开Firefox,以及全屏firefox。但是,找不到localhost:8080

我遗漏的端口/网络有什么问题吗?

0 个答案:

没有答案