简体   繁体   中英

Create an image from a Dockerfile

I am looking at a Docerfile like this:

FROM microsoft/aspnetcore:2.0 AS base

# Install the SSHD server
RUN apt-get update \
  && apt-get install -y --no-install-recommends openssh-server \
  && mkdir -p /run/sshd \
  && echo "root:Docker!" | chpasswd
#Copy settings file. See elsewhere to find them. 
COPY sshd_config /etc/ssh/sshd_config
COPY authorized_keys  root/.ssh/authorized_keys

# Install Visual Studio Remote Debugger
RUN apt-get install zip unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg

EXPOSE 2222

I am trying to create an image using this dockerfile. How can I do this? I have read many webpages over the last few hours eg this one https://odewahn.github.io/docker-jumpstart/building-images-with-dockerfiles.html , however they all seem to overcomplicate it as my research is telling me that there is only one command needed.

If Dockerfile is in your current directory, this command will build image and store it locally:

docker build -t "app:latest" .

Here is documentation for build command

Then you can run it in background with:

docker run -d -p 2222:2222 app

This command will create container and start it. Here is documentation for run command .

I'm not really sure what you consider 'overcomplicated' on that website?

There's one command on that site that says docker build -t "simple_flask:dockerfile" . . The only complication is that it adds a tag, which is explained directly underneath it

The only thing that might be simpler is not tagging it. so you do

docker build .

which means: build me an image. from the current directory.

Since you have a Docker file, you are required to do 4 additional steps:

  1. docker build -t <app-name> . : Building your image

  2. docker images : Check your image

  3. docker run -d -p 2222:8080 myapp : Run your image

  4. docker ps : Check running docker image

Refer Docker doc. for more detials

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM