Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run docker image produced by VS 2017

Docker noob here...

How does one properly run the docker image of your Asp.Net CORE app which is produced by Visual Studio 2017 at the command line?

docker run -it -d -p 80:32769 myappimage

does not appear to work properly (image runs, but I cannot browse to my app)

Note: I've simply created a sample ASP.Net Core Web App within Studio using the default template, and added Docker support (by clicking the "Add Docker support" checkbox.). Studio adds a dockerfile and some docker-compose files when you do this.

When Visual Studio "runs" the image (by pressing F5) - I can successfully browse to my application ( via "http://localhost:32789" or similar host port. App inside container is on port 80 ). But I cannot figure out the command to run it myself at the command line.

The standard Dockerfile that Studio adds to your project is...

FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebApplication2.dll"]
like image 732
HokieMike Avatar asked Apr 30 '17 16:04

HokieMike


People also ask

How do I run a docker image in Visual Studio?

Open the project in Visual Studio, and choose one of the following options: Select Docker Support from the Project menu. Right-click the project in Solution Explorer and select Add > Docker Support.

How do I run an existing image in docker?

To run an image inside of a container, we use the docker run command. The docker run command requires one parameter and that is the image name. Let's start our image and make sure it is running correctly. Execute the following command in your terminal.

How do I run a Dockerized project?

The easiest way to deploy a Dockerized application on a remote server is to transfer the application's image with docker pull and then use docker run . This runs the application in a container similar to how you'd do it in your development environment.


1 Answers

Yes, it is possible. Rebuild your solution in the Release configuration and try to run the docker-compose project with F5 to ensure the image is updated and your app is working fine. Then execute docker images console command. You'll see something like:

REPOSITORY   TAG      IMAGE ID       CREATED              SIZE
Your.App     latest   673b79a6bb3d   About a minute ago   294 MB

All you need is to run a new container from that image and map its exposed port to a localhost port. By default, the exposed port is 80 (look at Dockerfile). For example:

docker run -d -p 1234:80 --name some_name Your.App:latest

Then your app should become accessible at http://127.0.0.1:1234/.

Explanation:

If the Debug configuration is set, then empty non-workable images are created by Visual Studio. It manually maps the empty container to the filesystem to make possible debugging, "Edit and Continue" features and so on. This is why dev image is useless without Visual Studio. Build the image in the Release configuration to make it usable.

The full publishing process is described in the documentation: Visual Studio Tools for Docker

Publishing Docker images

Once you have completed the develop and debug cycle of your application, the Visual Studio Tools for Docker will help you create the production image of your application. Change the debug dropdown to Release and build the application. The tooling will produce the image with the :latest tag which you can push to your private registry or Docker Hub.

like image 90
Ilya Chumakov Avatar answered Nov 16 '22 00:11

Ilya Chumakov