LoginSignup
2
1

More than 5 years have passed since last update.

DockerとC言語でHelloWorldする

Posted at

概要

C言語の簡易な実行環境をDokcerで構築した時の作業メモ。
Ubuntu16.04環境で構築しました。

内容

  • フォルダ構成
- clang_test
  - Dockerfile
  - main.c
  • Dockerfileを作成
FROM ubuntu:16.04

RUN apt-get update && \
    apt-get install -y sudo

RUN sudo apt-get install -y \
    build-essential \
    vim
  • main.cを作成
main.c
#include <stdio.h>

int main()
{
  puts("Hello World.");
  return 0;
}
  • Dockerコンテナを立ち上げる
$ cd clang_test
$ docker build -t ubuntu/clang:16.04 .
$ docker run -it -d -v {clang_testの絶対パス}:/home --name clang {イメージID} bash
$ docker exec -it clang bash
  • main.cをコンパイル
# clangコンテナ内で実行
$ cd /home
$ cc -o main main.c
$ ./main
Hello World.
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1