6 Replies - 622 Views - Last Post: 05 June 2020 - 09:40 AM

#1 O'Niel   User is offline

  • D.I.C Addict

Reputation: 26
  • View blog
  • Posts: 598
  • Joined: 13-September 15

Dockerfile

Posted 19 May 2020 - 08:49 AM

Hi

In a tutorial I just executed the following:
vim Dockerfile
FROM ubuntu
MAINTAINER ONiel
RUN apt-get update && apt-get install -y apache2
docker build -t oniel/ubuntu:apache .


What this does when docker build... is executed is just creating a new dockerimage derived from the ubuntu-image. And then executes apt-get update.. on that image.

Couldn't I also just make a new image, and exeucte apt-get update.. on it manually and save it?
And what if I want to do multiple runs?

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Dockerfile

#2 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1033
  • View blog
  • Posts: 3,966
  • Joined: 13-June 14

Re: Dockerfile

Posted 19 May 2020 - 08:54 AM

View PostO, on 19 May 2020 - 04:49 PM, said:

Couldn't I also just make a new image, and exeucte apt-get update.. on it manually and save it?


I don't really get what you mean by this, as that's what you're doing in the Dockerfile. The point of having the image is so that you can create multiple containers from it. You set things up in the Dockerfile (like installing the software you need) so you don't have to do that for each container you start.

Quote

And what if I want to do multiple runs?


Again, what do you mean here?
Was This Post Helpful? 0
  • +
  • -

#3 O'Niel   User is offline

  • D.I.C Addict

Reputation: 26
  • View blog
  • Posts: 598
  • Joined: 13-September 15

Re: Dockerfile

Posted 19 May 2020 - 09:23 AM

What if I want multiple RUN commando's in one Dockerfile?

RUN cmd1
RUN cmd2

OR
RUN [cmd1, cmd2]

?
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1033
  • View blog
  • Posts: 3,966
  • Joined: 13-June 14

Re: Dockerfile

Posted 19 May 2020 - 09:36 AM

What's stopping you? AFAIK, there's no restriction on that.

Of course, check the docs though.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7463
  • View blog
  • Posts: 25,113
  • Joined: 05-May 12

Re: Dockerfile

Posted 19 May 2020 - 06:35 PM

Hopefully he'll confirm, but I think that what he is asking is that with the current approach of using the Dockerfile, there are all these steps that need to be executed just to build an environment to be able to execute cmd1. Then the the same operations need to happen again to run cmd2. He is asking if there is a way to make an image of the results of the Dockerfile, so that he can just restore that image and run cmd1 and then restore the image again and run cmd2.
Was This Post Helpful? 0
  • +
  • -

#6 O'Niel   User is offline

  • D.I.C Addict

Reputation: 26
  • View blog
  • Posts: 598
  • Joined: 13-September 15

Re: Dockerfile

Posted 05 June 2020 - 09:22 AM

Alright. Thanks.

I am trying to execute this tutorial code:
FROM alpine
RUN apk update && apk add nodejs COPY . /app
WORKDIR /app
CMD ["node","index.js"]



index.js is
var os = require("os");
var hostname = os.hostname();
console.log("hello from " + hostname);



When I run
docker image build -t hello:v0.1 .


I get the following error:
Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM alpine
 ---> a24bb4013296
Step 2/4 : RUN apk update && apk add nodejs COPY . /app
 ---> Running in 3b84bb36cbc5
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
v3.12.0-45-g0e4d4e3558 [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.0-47-gda1c1b9ae4 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
OK: 12729 distinct packages available
ERROR: unsatisfiable constraints:
  . (missing):
    required by: world[.]
  /app (missing):
    required by: world[/app]
  COPY (missing):
    required by: world[COPY]
The command '/bin/sh -c apk update && apk add nodejs COPY . /app' returned a non-zero code: 3



The COPY part is not working...
Was This Post Helpful? 0
  • +
  • -

#7 O'Niel   User is offline

  • D.I.C Addict

Reputation: 26
  • View blog
  • Posts: 598
  • Joined: 13-September 15

Re: Dockerfile

Posted 05 June 2020 - 09:40 AM

Solved... COPY was on same line as APT UPDATE
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1