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"]
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.
You are confusing here something. When you run your project with F5 in Visual Studio 2017, you run it with IISExpress on a randomly configured port.
In Docker you don't have IISExpress, there your app is only hosted by Kestrel (Kestrel is always used even behind IIS/IISExpress, but they act as reverse proxy).
The default port for Kestrel is 5000, but you can also configure it. See my post here for more detail on which methods you have to configure the listening ip/port.
Related
I created standard ASP.NET Core Web API .NET 5 project in .NET with Docker file automatically created. I did not select option "Configure for HTTPS".
When I run this project as docker container from Visual Studio then everything is fine, I can access swagger UI and hit RESRT API endpoints.
When I build the image and run it manually then it does not work.
I build it like this:
D:\temp\WebApplication1>docker image build -t kicaj29/webapplication1:1.0.0 -f WebApplication1/Dockerfile .
and run like this
docker run -p 8855:80 kicaj29/webapplication1:1.0.0
The container is running but when I try to access it using address http://localhost:8855/swagger/index.html then I get info that the page cannot be found.
Probably Visual Studio adds some extra staff but I cannot identify it.
Any ideas how to solve it?
-Jacek
For Swagger to be available, you need to run the app in development mode. You do that by setting the ASPNETCORE_ENVIRONMENT variable to 'Development'. If you change the docker run statement to
docker run -p 8855:80 -e ASPNETCORE_ENVIRONMENT=Development kicaj29/webapplication1:1.0.0
When you do that, the Swagger UI becomes available on http://localhost:8855/swagger
You can also add the line
ENV ASPNETCORE_ENVIRONMENT=Development
to your Dockerfile. Then it'll be in development mode by default.
I created a dotnetcore WebAPI with Visual Studio 2019 16.0 Preview which has docker support. I'm using the windows container and is able to execute the application from Visual Studio IDE. I can also debug the app.
The way I used to run dotnetcore WebAPI app was execute the dotnetcore run from the project folder in the command prompt. The project will be rebuilt if I make a change in the code. I attach the Visual Studio to the dotnetcore process to debug.
How can I do the same for the application that runs inside a Docker
Container?
What command that I need to run from the project folder?
You need to read on docker. You can find some very good documentation here: https://docs.docker.com/
You need to build an image first. Go to your application folder where your Dockerfile is stored open powershell and type
docker build .
your image will be build and then confirm that you have a new image by
docker images
with the command above you can see all the available images that you have locally.
After finding the right image you run
docker run -p 8080:8080 <image name or id>
-p is port mapping, it is needed because because docker has its own network.
The above are the absolute basic commands. Take a look at the documentation url it will help you a lot.
I've been attempting to move an application to the cloud for a while now and have most of the services set up in pods running in a k8s cluster. The last piece has been giving me trouble, I need to set up an image with an older piece of software that cannot be installed silently. I then attempted in my dockerfile to install its .net dependencies (2005.x86, 2010.x86, 2012.x86, 2015.x86, 2015.x64) and manually transfer a local install of the program but that also did not work.
Is there any way to run through a guided install in a remote windows image or be able to determine all of the file changes made by an installer in order to do them manually?
You can track the changes done by the installer following these steps:
start a new container based on your base image
docker run --name test -d <base_image>
open a shell in the new container (I am not familiar with Windows so you might have to adapt the command below)
docker exec -ti test cmd
Run whatever commands you need to run inside the container. When you are done exit from the container
Examine the changes to the container's filesystem:
docker container diff test
You can also use docker container export to export the container's filesystem as a tar archive, and then docker image import to create an image from that archive.
I developed an HTTP server which implements RESTful API specified by our client. Currently my workstation (Centos 7.4 x86_64) and everything else is working. Now I need to ship it as Centos 7.4 docker image.
I read the getting started guide and spent some time browsing the documentation but am still not sure how to proceed with this.
Basic Steps
Download Centos image from here
Run Centos image on my workstation and copy everything into it.
Make an appropriate changes so that server is started via systemd.
In step 3 : I am not sure how to do root/sudo inside the docker image.
I think what you are looking for is the Dockerfile reference https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
It's a file name Dockerfile that sits in the root of your project. You specify in this file which commands you want to run on top of the base image.
for example, from your use case:
FROM centos7.4.1708
COPY <your files> /opt/
CMD ["program.exe" "-arg" "argument"]
FROM - defines the base image
COPY - copies files from the folder you run the command from to the image
CMD - runs this command when the container starts
Build with docker build . -t image-name
Run with docker run image-name
I follow the example to publish an ASP.NET app to Docker on Linux with Visual Studio.
However each time I modify the code and publish it again. It seems to create a new container and image. So it is sort of wasting space.
So what is the best practices here? How can I use the same container and just overwrite the previous image?
EDIT
Dockerfile
FROM microsoft/aspnet:1.0.0-rc1-update1
ADD . /app
WORKDIR /app/approot
ENTRYPOINT ["./web"]
How can I use the same container and just overwrite the previous image
You can't. For a new image you need to create a new container. Keep in mind that it is early days for docker on windows, the VS docker extension is preview software.
Probably not so easy with azure but generally you would set up a clean up cron that periodically purges old images and stopped containers on the docker host.