Coder Social home page Coder Social logo

alpine 0.31.0 COPY failed about deno_docker HOT 9 CLOSED

aadamsx avatar aadamsx commented on April 28, 2024
alpine 0.31.0 COPY failed

from deno_docker.

Comments (9)

hayd avatar hayd commented on April 28, 2024 1

Oh, I see your snippet is from the README! Sorry about that, I will amend.

from deno_docker.

hayd avatar hayd commented on April 28, 2024 1

Oh, maybe this was the issue:

NOTE: I have no deps.ts file in my source directory

If you don't have a deps.ts then you should remove the deps.ts lines in the Dockerfile.

I recommend to have a deps.ts as this caches all of the dependencies and allows quicker iteration cycle (as dependencies don't need to be downloaded/compiled on each build).
In your case deps.ts would be:

// deps.ts
export { Application, Router } from "https://deno.land/x/oak/mod.ts";

// main.ts
import { Application, Router } from "./deps.ts";

const router = new Router();
router
...

from deno_docker.

hayd avatar hayd commented on April 28, 2024 1

If you change to

app.listen(`:1993`);

your example works (at least for me).

I suspect this is something to do with internal IP addresses inside the container... 🤷‍♂
(Perhaps https://stackoverflow.com/q/24319662/1240268 ?)


Note: This is a very simple example only meant to get my into a Docker container. I only have 3 files in the root of the directory (no other directories):

This should be sufficient (COPY and fetching deps.ts, then everything else) for even more complex deno projects (although the deno-lambda one I link to above is more complicated - since I want to aggressively cache compilation inside layers).

I'd eventually like to use this Docker container on an Azure App Service.

It reads in the documentation that this ought to be straightforward... it looks like the port to EXPORT will have to be 8000 (instead of 1993).

https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image

from deno_docker.

aadamsx avatar aadamsx commented on April 28, 2024 1

Yes, just changing the line to:

app.listen(`:1993`);

Worked for me as well.

from deno_docker.

aadamsx avatar aadamsx commented on April 28, 2024 1

Maybe I will.

Also, I also got this working locally by using this line too:

app.listen(`0.0.0.0:8000`);

from deno_docker.

hayd avatar hayd commented on April 28, 2024

Can you try with:

COPY deps.ts .

Similarly:

ADD . .

See the example: https://github.com/hayd/deno-docker/blob/master/example/Dockerfile

(And a more complicated example in deno-lambda)

from deno_docker.

aadamsx avatar aadamsx commented on April 28, 2024

Added deps.ts file:

export { Application, Router } from "https://deno.land/x/oak/mod.ts";

Modified main.ts file for deps.ts:

import { Application, Router } from "./deps.ts";

const router = new Router();
router
  .get("/", context => {
    console.log('called /');
    context.response.body = "Hello world!";
  })
  .get('/fetch', async context => {
    console.log('called /fetch');
    const res = await fetch('https://pokeapi.co/api/v2/pokemon/ditto/')
      .then(res => res.json());
    context.response.body = JSON.stringify(res);
  });

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

console.log('started on 1993');

app.listen(`127.0.0.1:1993`);

Updated the Dockerfile:

FROM hayd/deno:alpine-0.31.0

EXPOSE 1993

WORKDIR /app

# Prefer not to run as root.
USER deno

# Cache the dependencies as a layer (this is re-run only when deps.ts is modified).
# Ideally this will download and compile _all_ external files used in main.ts.
COPY deps.ts .
RUN deno fetch deps.ts

# These steps will be re-run upon each file change in your working directory:
ADD . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno fetch main.ts

ENTRYPOINT ["deno", "run", "--allow-net", "main.ts"]

Now it builds:

docker build -t app .

And runs:

docker run -it --init -p 1993:1993 app
started on 1933

But when I try to curl > curl http://localhost:1993

curl: (52) Empty reply from server

Note: This is a very simple example only meant to get my into a Docker container. I only have 3 files in the root of the directory (no other directories):

  • depts.ts
  • Dockerfile
  • main.ts

Just in case it matters somehow or you have some insight on this: I'd eventually like to use this Docker container on an Azure App Service.

Thank you for the help so far.

from deno_docker.

aadamsx avatar aadamsx commented on April 28, 2024

Just wanted to follow up.

I was able to deploy this image to ACR and then created an Azure web app from that running Deno. So basically a containerized Deno web app in Azure -- one step from serverless Deno.

Thanks again for your help!

from deno_docker.

hayd avatar hayd commented on April 28, 2024

Great! If you ever write anything up about this I'll happily link to it in the project (I think people will find it useful in the future).

from deno_docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.