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.
Related
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 am working on trying to improve my development environment using Docker and Go but I am struggling to get auto reloading in my containers working when there is a file change. I am on Windows running Docker Desktop version 18.09.1 if that matters.
I am using CompileDaemon for reloading and my DockerFile is defined as follows
FROM golang:1.11-alpine
RUN apk add --no-cache ca-certificates git
RUN go get github.com/githubnemo/CompileDaemon
WORKDIR /go/src/github.com/testrepo/app
COPY . .
EXPOSE 8080
ENTRYPOINT CompileDaemon -log-prefix=false -directory="." -build="go build /go/src/github.com/testrepo/app/cmd/api/main.go" -command="/go/src/github.com/testrepo/app/main"
My project structure follows
app
api
main.go
In my docker-compose file I have the correct volumes set and the files are being updated in my container on when I make changes locally.
The application is also started correctly using CompileDaemon on its first load, its just not ever updated on file changes.
On first load I see...
Running build command!
Build ok.
Restarting the given command.
Then any changes I make are not resulting in a restart even though I can connect to the container and see that the changes are reflected in the expected files.
Ensure that you have volumes mounted for the services you are using, it is what makes the hot reloading work inside of a Docker container
See the full explanation
Proper way of installing the Compile Daemon is
RUN go install -mod=mod github.com/githubnemo/CompileDaemon
Reference: https://github.com/githubnemo/CompileDaemon/issues/45#issuecomment-1218054581
I created an Angular 7 application using VS2017 by following this documentation. The application is working fine in local machine, but I want to add docker support for this angular application, and also deploy it into either local docker or local kubernetes.
So, can anyone help on that issue?
I do not know the book that you referenced. But in general the steps would be:
- Try to run your application locally from command line (I guess it can be started with dotnet run).
- Create a Dockerfile
- Use official docker images that already include dotnet framework as Base-Image (e.g.: from microsoft/dotnet:runtime)
- In your Dockerfile you can add as much as you want (install dependencies, run unit-tests, etc.), but to keep it simple the following should be enough:
Dockerfile:
from microsoft/dotnet:runtime
COPY . .
RUN dotnet restore
RUN dotnet build
ENTRYPOINT ["dotnet", "run"]
To optimize for performance you can use multi-stage docker images and split your Dockerfile into build and runtime
Note, that I didn't read your tutorial, but this is how I would start with preparing for docker
To work with kubernetes you can simply push your docker image (docker build -t <your-tag>) to a docker-registry, which your kubernetes cluster has access to and create a k8s-deployment for that contains that image. Locally you don't need a docker-registry but can simply kubectl run ...
See:
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
and https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/
I know how to deploy custom KeyCloak theme in Windows using both ways as stated here:
Copy-paste theme in themes directory
Using archive deploy
Can someone please suggest how to do this in docker?
This is what I did:
Created Dockerfile like below
FROM jboss/keycloak
COPY ./themes/<yourThemeName>/ /opt/jboss/keycloak/themes/<yourThemeName>/
Built new docker image from this file
docker build -t <yourDockerHubUserName>/keycloak .
Run this docker image
docker container run --name <someContainerName> -p 8080:8080 -e
KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=password
<yourDockerHubUserName>/keycloak
Check if new theme shows up by logging into admin console at
http://localhost:8080/auth and go to realms/themes click drop down list of themes and you should see <yourThemeName>
Finally, did the following way. Copy the customized theme named MyTheme at some path say "/root/" from windows to the linux server using FileZilla or similar tools.
To list all the docker instances that are running on the server, use the following command:
docker ps
Find the container in which keycloak is running and pick its container id.
Now use the following command to copy the custom theme in the themes folder.:
docker cp /root/MyTheme/.
your_keycloak_container_id:/opt/jboss/keycloak/themes/MyTheme
Restart server.
Best way is by far to bundle the theme into a .jar file and drop it here: /opt/keycloak/providers.
Here you have a plugin that implement this approach.
You can also use keycloakify, it bundles the theme for you.
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.