How to add the file in docker - docker

I am new to docker, I installed docker as per the instructions provided in the official site.
# build docker images
docker build -t iky_backend:2.0.0 .
docker build -t iky_gateway:2.0.0 frontend/.
Now, while I am running these commands in the terminal after the installation of docker, I am getting the below error. I tried with by adding sudo also. But no use.
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/esh/Dockerfile: no such file or directory

Your docker images should execute just fine (may require sudo if you are unable to connect to docker daemon).
docker build requires a Dockerfile to present at the same directory (you are executing at your home folder - dont do that) or you need to use -f to specify the path instead of .
Try this:
mkdir build
cd build
create your Dockerfile here.
docker build -t iky_backend:2.0.0 .
docker images

Related

How to run a private Docker image

docker run -i -t testing bash
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown.
I created the image in Docker Hub , it is private image.
FROM scratch
# Set the working directory to /app
WORKDIR Desktop
ADD . /Dockerfile
RUN ./Dockerfile
EXPOSE 8085
ENV NAME testing
This is in my Dockerfile
I tired to run it, when i run docker images i am getting the details
I think you need to do login in command prompt.useing below command.
docker login -u username -p password url
Apart from the login which should not cause these, as you build an image on your local system which I assume it should exist on local system which will only pull image if not exist on local, the real reason is you are building an image from scratch and there are no binaries in scratch image, even no bash or sh.
Second mistake:
RUN ./Dockerfile
Your Dockerfile is a file, not binaries, while here you are trying to execute using RUN directive.
While scratch appears in Docker’s repository on the hub, you can’t
pull it, run it, or tag any image with the name scratch. Instead, you
can refer to it in your Dockerfile. For example, to create a minimal
container using scratch:
FROM scratch
COPY hello /
CMD ["/hello"]
While here hello can be an executable file such as a C++ compiled file.
Docker scratch image
But what I would suggest to say "hello" in Docker is to use Busybox or Alpine as a base image which has a shell and both are under 5MB.
FROM busybox
CMD ["echo","hello Docker!"]
now build and run
docker build -t hello-docker .
docker run --rm -it hello-docker

how can i start using docker container using Dockerfile

I am using ubuntu 18.04
I have docker-ce installed
I have a file named Dockerfile
I didn't have any other files
how can I start using this container
Firstly you need to build an image from Dockerfile. To do this:
Go to the directory containing Dockerfile
Run (change <image_name> to some meaningful name): docker build -t <image_name> .
After image is built we can finally run it: docker run -it <image_name>
There multiple options how the image can be run so I encourage you to read some docs.

Create container from local file

I have a file called Dockerfile which contains a Docker configuration.
If I try to build a container from the file:
docker build Dockerfile
I get:
unable to prepare context: context must be a directory: C:\Path\To\Dockerfile
So how can I create a Docker container from a local configuration file?
According to https://docs.docker.com/engine/reference/commandline/build/ the parameter to docker build is not the Dockerfile, but a directory or URL containing the Dockerfile. So your command should rather be
docker build .
or even better, considering docker defaults to the current dir:
docker build
If your Dockerfile happens do be named differently (it really shouldn't), you can tell docker to use it by passing it to the -f or --file option:
docker build -f MyDockerfile

Docker image versioning and lifecycle management

I am getting into Docker and am trying to better understand how it works out there in the "real world".
It occurs to me that, in practice:
You need a way to version Docker images
You need a way to tell the Docker engine (running on a VM) to stop/start/restart a particular container
You need a way to tell the Docker engine which version of a image to run
Does Docker ship with built-in commands for handling each of these? If not what tools/strategies are used for accomplishing them? Also, when I build a Docker image (via, say, docker build -t myapp .), what file type is produced and where is it located on the machine?
docker has all you need to build images and run containers. You can create your own image by writing a Dockerfile or by pulling it from the docker hub.
In the Dockerfile you specify another image as the basis for your image, run command install things. Images can have tags, for example the ubuntu image can have the latest or 12.04 tag, that can be specified with ubuntu:latest notation.
Once you have built the image with docker build -t image-name . you can create containers from that image with `docker run --name container-name image-name.
docker ps to see running containers
docker rm <container name/id> to remove containers
Suppose we have a docker file like bellow:
->Build from git without versioning:
sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments
in here:
fecomments is branch name and comments is the folder name.
->building from git with tag and version:
sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments -t lordash/comments:v1.0
->Now if you want to build from a directory: first go to comments directory the run command sudo docker build .
->if you want to add tag you can use -t or -tag flag to do that:
sudo docker build -t lordash . or sudo docker build -t lordash/comments .
-> Now you can version your image with the help of tag:
sudo docker build -t lordash/comments:v1.0 .
->you can also apply multiple tag to an image:
sudo docker build -t lordash/comments:latest -t lordash/comments:v1.0 .

\Dockerfile: The system cannot find the file specified

I have created a docker file to use node.js and nginx. When I run docker -t build <my docker file name> . I get the following error:
Dockerfile: The system cannot find the file specified.
Then in the docker file directory I created a folder name web and place my index.html and style.css file in it.
Question is: Any idea why I am getting this error?
The command docker -t build <my docker file name> . is being misused. It should be:
docker build -t <image-name> -f dockerFile .
where dockerFile is the name you gave to the Dockerfile.
The -t option specifies the tag or name to give to the Docker image.
The -f must be used, if you name the Dockerfile something other than Dockerfile
The . specifies the docker build context.

Resources